Hello I need help with this code, I'm trying to get the player to move a set distance forward when I press Q but right now its pretty inconsistent, when I press Q, it will somtimes go straight forward and other times start making me go right or left randomly. Code (CSharp): private void Teleport() { //if the q key is pressed //move the transform forward if (Input.GetKeyDown(KeyCode.Q)) { transform.position = transform.position + new Vector3(transform.position.x, 2, 0); Debug.Log("QQQQQ"); } }
if you want to move 2 meters forward (at viewing direction) Code (CSharp): transform.position += transform.forward * 2; *works if players Z blue axis is forward, if not, use the others: .right, .up, .. https://docs.unity3d.com/ScriptReference/Transform-forward.html if want to move in worldspace, https://docs.unity3d.com/ScriptReference/Vector3-forward.html