- Home /
Need help with char movement.
Hi guys.Im trying out to make a game with Aircrafts.So here is the thing...I wanna make my charachter to rotate with the mouse (Well i did that thanks to mouse look :D) but when for example the user has moved the mouse on Y direction...the aircraft to rotate there and go straight to that direction.(again:rotation made with mouse look)
I tried transform.position and direction and other things but i CAN'T!
Can you help me please? :)
Can you not use the WASD to move the aircraft and the mouse look to rotate around?
Answer by Statement · Jan 06, 2011 at 08:03 PM
If I understood your question, here's a simple aircraft script.
public class Aircraft : MonoBehaviour { public float flightSpeed = 1.0f; public float yawSpeed = 250.0f; public float pitchSpeed = 250.0f;
void Update()
{
float time = Time.deltaTime;
float yaw = Input.GetAxis("Mouse X") * yawSpeed * time;
float pitch = Input.GetAxis("Mouse Y") * pitchSpeed * time;
transform.Rotate(Vector3.left, -pitch);
transform.Rotate(Vector3.forward, -yaw);
transform.Translate(Vector3.forward * flightSpeed * time);
}
}
You probably want to change flightSpeed a bit in case you find the motion too slow. It should be attached to a camera. It uses mouse controls to fly sort of like an airplane.
It is full of errors.Its C# script right?But in .js is also full of errors...Where did you find the script?
WAIT i fixed the errors and its almost what i want!!! Thanks you have me one step further from my goal!!!
Answer by The_r0nin · Jan 06, 2011 at 04:23 PM
I'll refer you to my thread on this issue to help get you started: Click Here.
I never got a satisfactory answer, so hopefully you can take the solution a step farther. I ended up abandoning this approach and went with an approach that rotates the aircraft based on whether the mouse is to the right/left of the center of the screen and applies pitch based on whether the mouse is above/below the center. If you are interested, I'll post some of that code here when I get the chance...
Your answer
![](https://koobas.hobune.stream/wayback/20220613094312im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Basic Character Transform with Joystick 1 Answer
Character movement range in strategy game. 2 Answers
Why am I not moving forward? 1 Answer
Third Person type Rpg movement 0 Answers
Why is Character just moving "smooth" when camera follows? 0 Answers