Question by
Dylan_the_nipple · Dec 25, 2015 at 12:52 AM ·
mousecontrolvehicleflying
How do i get an object to follow my mouse on all axis?
Hi, I am fairly new to coding, but i'm getting used to it. Me and a friend are making a game, with flying snow speeders. This is the code I have atm (for control):
public class TheSnowspeeder : MonoBehaviour {
public float moveSpeed = 10f;
public float turnSpeed = 100f;
void FixedUpdate ()
{
if(Input.GetKey(KeyCode.UpArrow))
transform.Rotate(-Vector3.right * turnSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.LeftShift))
transform.Translate(Vector3.up * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.RightArrow))
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.DownArrow))
transform.Rotate(Vector3.right * turnSpeed * Time.deltaTime);
if (Input.GetAxis ("Mouse X") < 0)
;
if (Input.GetAxis ("Mouse X") > 0)
;
}
}
As you can see, I am using keys for control. But I would like to make it mouse movement, how can I achieve this? If you need an example, like war thunder or star wars battlefront flying.
I understand I only have x axis but it wont move no matter what axis using mouse, please help!
Comment
Your answer
Follow this Question
Related Questions
Using Input.GetKey(KeyCode.Mouse0)) on iOS and Android 0 Answers
movement control with mouse clicks 0 Answers
Who can help me with these error messages? 0 Answers
Vehicle throttle cut with negative forward velocity 0 Answers
Event on mouse up 2 Answers