Hmm this is borderline to in depth an answer for me to want to give right now I should be working on my own game! I guess I’ll try a quick one though. I haven’t made a flying game with the controls like this though so this is just what I presume would work…
This code will work for aiming assuming it is a first person perspective.
I cannot take credit for this aim script, I used this when I was first learning, not sure where it’s from anymore. It may have been altered from it’s original state as well so you can mess with the numbers.
using UnityEngine;
using System.Collections;
/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation
/// To make an FPS style character:
/// - Create a capsule.
/// - Add the MouseLook script to the capsule.
/// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// - Add FPSInputController script to the capsule
/// -> A CharacterMotor and a CharacterController component will be automatically added.
/// - Create a camera. Make the camera a child of the capsule. Reset it's transform.
/// - Add a MouseLook script to the camera.
/// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLookScript : MonoBehaviour
{
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 10F;
public float sensitivityY = 10F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
void Start ()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
//lateUpdate(); ?
void Update ()
{
if ((axes == RotationAxes.MouseXAndY) && (GlobalDataScript.cursorState==1))
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if ((axes == RotationAxes.MouseX) && (GlobalDataScript.cursorState==1))
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else if (GlobalDataScript.cursorState==1)
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
}
This code for other controls:
int flyingSpeed = 100;
int speedChange = 20;
int rotationInt = 2;
Update()
{
if (Input.GetKeyDown (KeyCode.W))
{
flyingSpeed += speedChange;
}
if (Input.GetKeyDown (KeyCode.S))
{
flyingSpeed += -speedChange;
}
if (Input.GetKey (KeyCode.A))
{
transform.RotateAround (transform.position, transform.up, -rotateInt);
}
if (Input.GetKey (KeyCode.D))
{
transform.RotateAround (transform.position, transform.up, rotateInt);
}
}
FixedUpdate()
{
transform.position += transform.forward * flyingSpeed * Time.deltaTime;
}
You might have to adjust some variables like the speed, the speed change, and the rotationInt to get it to fly how you want.
If you apply these scripts to the plane gameObject and set the camera to be the central transform position this work. Just make sure if you are using a rigid body you turn off the gravity.
I’m not sure how well this will work like I said I never made a flying game like this. But this should at least get you started.
@D3m0nE Can you bake a Cake for me? If not, why should I write a script for you?
– Benproductions1id you dont want to,, then dont,, just show me where i can find it
– D3m0nEhttp://lmgtfy.com/?q=unity+airplane+controller+script
– DracoratIt's one of those questions that should not have left the queue.
– Unitraxx