- Home /
The question is answered, right answer was accepted
Making an AirPlane follow mouse
Hi! I am trying to make an AirPlane in my game, but i am having some troubles. I tried to make it rotate, but it wouldn't be the best idea to make all the controls be in the keyboard, so i am trying to make something with the mouse.
I wanted to make something like in World of Warplanes: https://www.youtube.com/watch?v=Kqw80hQplmk
I already made the machine guns for the airplane, and i made a simple script that make the airplane go forward everytime, and make possible for players to MOVE to left and right using A and D. Here's the script:
using UnityEngine;
using System.Collections;
public class PlaneControl : MonoBehaviour
{
public float speed = 1f;
void Update()
{
Vector3 moveDir = Vector3.zero;
transform.position = transform.position + ((transform.rotation * transform.forward) * speed * Time.deltaTime);
moveDir.x = Input.GetAxis("Horizontal"); // get result of AD keys in X
transform.position += moveDir * speed * Time.deltaTime;
}
}
It's C#. How do i make my plane ROTATE to left and right and ROTATE up and down using the mouse? Can someone help me? I need to do this and i don't know how, i always get confused about those things because the mouse can't be referenced like the other objects because in reality it isn't part of the game, and i don't know how to make an input for it or something =(
Answer by Namey5 · Oct 26, 2016 at 07:45 AM
There are inputs set up by default in Unity for mouse movement.
transform.Rotate (Vector3.right * rotationSpeed * Input.GetAxis ("Mouse X")); //Uses the left/right mouse movement to rotate the object.
You can find all available inputs in the Input window (Edit>Project Settings>Input).
Thanks! Didn't know that there was an input for the mouse. Well, that's kind of stupid lol
Follow this Question
Related Questions
position.Set vs. position = new Vector3() 0 Answers
Distribute terrain in zones 3 Answers
GetMouseButtonDown(1) true in multiple frames 1 Answer
Make player face same direction as camera. 4 Answers
Make two successif selection with mouse? 2 Answers