move up and down ok, but rotation messed

Hi,

I never developed for unity, but i did a lot of work for 2d using hge/oslib(psp).
So i’m a little lost now.

I created the following code:

	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.magnitude*(float)Time.deltaTime;
		if(Input.GetKey(KeyCode.S))newValues[0]-=this.speed*transform.forward.magnitude*(float)Time.deltaTime;
		
		
		transform.position = new Vector3(transform.position.x, transform.position.y, (float)newValues[0]);
		newValues[1]=0;

So, when i rotate and move he rotates ok, but it moves like the cam never rotated.
If i move 10 degrees to the right the movement stills in the only in the z axis.
How i correct that?

Thanks

I’m not sure I fully understand your question, but I think what is happening is that you’re setting the absolute value of Z to be a tiny value, rather than adding to it.

What you want to do is transform.position.z + (float)newValues[0]