Quantcast
Channel: Questions in topic: "around"
Viewing all articles
Browse latest Browse all 101

Look Behind Me While Still Moving Forward

$
0
0
I am trying to automatically run forward while being able to simultaneously look behind me (using input) however the problem I encounter is that when I press the button to look behind me my character starts running in that direction. I want the user to look behind them while still running forward. Please help. This is the code to run forward using UnityEngine; using System.Collections; public class Run_Forward : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.A)) transform.position += Vector3.right*4; if (Input.GetKeyDown(KeyCode.D)) transform.position += Vector3.left*4; transform.Translate(0, 0, .2f); } } And this is the code to turn around using UnityEngine; using System.Collections; public class Rotate : MonoBehaviour { public Transform target; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.T)) transform.LookAt(target); } }

Viewing all articles
Browse latest Browse all 101

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>