- Home /
Mouselook forward wrong? ...
Hi,
This might be a bit of a silly question but I can't find the answer! I've modified the standard "MouseLook" controller to move the camera forward when I press "W" by adding the following code to the update function :
if(Input.GetAxis("Vertical") >0) { this.transform.Translate(this.transform.forward); } else{ if(Input.GetAxis("Vertical") <0) { this.transform.Translate(this.transform.forward *-1); } }
The only bugger is, the definition of "forward" seems to be a little erratic - following a rotation, it moves in the wrong direction.
Any suggestions?
Cheers!
Answer by Malcor · Aug 06, 2012 at 04:53 PM
I don't know the answer, maybe tidy up the "If" statement. Like so. Helps to find problems later. I would love to know the answer to this though.
if(Input.GetAxis("Vertical") >0) { this.transform.Translate(this.transform.forward); } else if(Input.GetAxis("Vertical") <0) { this.transform.Translate(this.transform.forward *-1); } else if (Input.GetAxis("Vertical") == 0) //Do nothing }
Your answer
Follow this Question
Related Questions
how to ignore transform.position.y 3 Answers
GameObject facing fowards 1 Answer
Mouse Look Script Acts Weird When Deactivated By Script 0 Answers
Setting an objects angle about a local axis without localEulerAngles? 0 Answers
Quaternions acting up 1 Answer