- Home /
AirPlane Script?
Hello everyone
i just need very little help here,
i'm searching for simple Airplane Script
W to Increase the speed S to Dicrease the speed A,D To Rotate
Fly up and down depending on MOUSE Aim,
[C#]
i hope you can help me, and how i can make it fly
should i use the same of FPS but change the "Graphic" Part?
@D3m0nE Can you bake a Cake for me? If not, why should I write a script for you?
id you dont want to,, then dont,, just show me where i can find it
It's one of those questions that should not have left the queue.
Answer by RyanZimmerman87 · Apr 10, 2013 at 11:47 PM
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.
well i'm not even gonna look at it 'cause i'm appalled by the question, but thumbs-up for effort.
Why would you answer properly to an unproper question? Good job though...
thank you, Its kinda work :) i just need to add some effect xD
btw : should i change the Drag or Angular Drag or something?
If you want drag and angular drag, you are going for a simulation, not just a transformation-control plane, but a real physics-controlled plane, and that needs a whole lot more codes than these.
Your answer
Follow this Question
Related Questions
How to create air in the rooms 1 Answer
Warp drive and sound on key press 0 Answers
How do i keep an object from rotating? 2 Answers
Space Torpedo 1 Answer
Weapons Range Projectile script 1 Answer