I am starting my development with Unity. I am doing something like this:
if(Input.GetKey(KeyCode.A))newValues[1]-=this.turnSpeed*(float)Time.deltaTime; if(Input.GetKey(KeyCode.D))newValues[1]+=this.turnSpeed*(float)Time.deltaTime; transform.Rotate(0, newValues[1], 0); if(Input.GetKey(KeyCode.W))newValues[0]+=this.speed*transform.forward.z*(float)Time.deltaTime; if(Input.GetKey(KeyCode.S))newValues[0]-=this.speed*transform.forward.z*(float)Time.deltaTime; transform.position = new Vector3(transform.position.x, transform.position.y, (float)newValues[0]);
So, I spin, and I can move, but it only moves in line Z, I know that I am causing a Z-specific movement. But with Javascript I can do something
transform.forward+=this.speed*transform.forward*(float)Time.deltaTime;
Therefore, I do not need to make a new vector process and copy it into a separate variable, and it works like a charm, using rotation and using it as an orientation for myself when it turns.
source share