- Home /
Problem changing rotation of 3rd Person Controller
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!
The fact that it is resetting the orientation of the ship, every time a WSAD key is pressed makes me suspect the problem lies with the 3rd person controller, that actually responds to these keypresses. Perhaps it does not use transform.Rotate(some amount)
like you do, but rather tranform.rotation= some value;
This would overwrite any rotation you may have applied previously. You mentioned binding the rotation to a key: I'd suggest you go "all-in", and do the same for the other two axis, making your own controller to ensure consistency.
Answer by livevlad · Jan 09, 2015 at 09:48 AM
To move your ship / plane to where it is looking, do something like :
this.transform.position += this.transform.forward * speed * Time.deltaTime;
// "this" is your ship
// "speed" is a float for .... the ship's speed