Hello,
I’m making a 2D game where you turn with A and D and go forward with W. I managed to get the rotating working but I can’t find out how to move towards the direction the object is facing.
#pragma strict
var turnright : KeyCode;
var turnleft : KeyCode;
var fwards : KeyCode;
var mspeed = 6;
function Update () {
// rigidbody2D.velocity =new Vector2(Input.GetAxis("Horizontal") * mspeed, Input.GetAxis("Vertical") * mspeed);
if (Input.GetKey(turnleft))
{
transform.Rotate(Vector3.forward * 1);
}
if (Input.GetKey(turnright))
{
transform.Rotate(Vector3.back * 1);
}
if (Input.GetKey(fwards))
{
}
}
turnright is set to D
turnleft is set to A
fwards is set to W
How can I make my object move towards the direction it is facing with speed = mspeed?