- Home /
question about turret on tank
Hello! i have question about my game. When i am driving my tank on mountain, and i am rotating my turret it is twisting in different directions, how can i fix it? here is script i am using: #pragma strict var speed : float = 5; var backspeed : float = -5; function Update() { if (Input.GetKey("z")) { transform.Rotate(0,speed*Time.deltaTime, 0,Space.World); } if (Input.GetKey("x")) { transform.Rotate(0,backspeed*Time.deltaTime, 0,Space.World); } if (Input.GetKey("d")) { transform.Rotate(0,speed*Time.deltaTime, 0,Space.World); } if (Input.GetKey("a")) { transform.Rotate(0,backspeed*Time.deltaTime, 0,Space.World); } }
and screenshot:
It looks like you are using Space.World when you should be using Space.self
Space.World will apply the rotations around the worlds axis alignment (typically the usual axis-aligned setup of Y is up). Space.self will apply the rotations around the local axis alignment of the object e.g your tanks up vector will always be pointing out of the top of the tank using this.
Give it a try and see if it works
Answer by jaj123 · Dec 14, 2013 at 02:54 PM
You need to rotate the turret around its local axis
if (Input.GetKey("z")) {
transform.Rotate(0,speed*Time.deltaTime, 0,Space.Self);
}
Your answer
Follow this Question
Related Questions
How can I rotate a tank's turret back to the starting turret position? 2 Answers
Rotate on Z axis 2 Answers
rotating a tank turret while the tank is rotating 3 Answers
Rotating turret floats off tank in a sideways circle. Cannon floats out of turret when rotating up. 0 Answers
Lock rotation of object 4 Answers