- Home /
Problem changing 3rd Person controller rotation
Hi,
Im new to Unity and i've been messing around with it for a while and i have encountered the following problem.
I used a 3rd person controller to create a ship that navigates through the scene just like if it was a character standing but in this case theres no gravity and the ship can move on the Y axis (it is able to go up and down)
The issue that im having right now is that, whenever the ship goes up (movement on Y axis) it basically "floats up".
Instead of this i'd like to have it be able to pitch up/down just like a plane.
The first thing I tried was adding the following code to the 3rd person controller to see if it would pitch up.
transform.Rotate(Vector3.left * Time.deltaTime);
By doing this the ship starts pitching up on load by itself, which is good (Ill bind the rotation to a key later on) but the problem is that whenever I press any "WASD" key to move the ship resets it's position back to flat and continues moving forward relative to the groud,or x and z axes. (And it wont pitch up anymore eventhough I have the Rotation line on the Update() function.)
Im thinking that by default, the 3rd peson controller uses the world axes to move forward and backwards and it is not moving relative to the ship's axes. Am i right here?
So, is there any way I can make the "W" key move the ship to where it is looking, instead of relative to the scene x and z axes?
Thanks everyone!
Answer by Juice-Tin · Jan 08, 2015 at 11:42 PM
transform.forward is a property that holds the direction of an object. So you can easily write:
transform.position = transform.position + transform.forward * Time.deltaTime;