N00b Question airplane movement

im brand new at scripting and the unity thing and i was wondering if someone could tell me how to make an .3ds object move like an airplane as in all the starwars space games.
thanks

Here’s a basic script:

// Make sure the z-axis is facing forward
// The object must have a rigidbody attached

// The ship's speed
var speed : float = 20.0;
var horTurnSpeed : float = 10.0;
var verTurnSpeed : float = 10.0;

function FixedUpdate ()
{
     // make the ship move at a constant forward speed.
     rigidbody.velocity = transform.forward * speed;
     var x : float = Input.GetAxis ("Vertical");
     var y : float = Input.GetAxis ("Horizontal");
     rigidbody.AddRelativeTorque (x * verTurnSpeed, y * horTurnSpeed, 0);
}

That you so much

hi there. i used the given code and added a line to turn the plane when user presses horizontal keys (to make it actually spin).

// Make sure the z-axis is facing forward
// The object must have a rigidbody attached

// The ship's speed
var speed : float = 20.0;
var horTurnSpeed : float = 10;
var verTurnSpeed : float = 10;

function FixedUpdate ()
{
    // make the ship move at a constant forward speed.
    rigidbody.velocity = transform.forward * speed;
	var x : float = Input.GetAxis ("Vertical");
	var y : float = Input.GetAxis ("Horizontal");
	rigidbody.AddRelativeTorque (x * verTurnSpeed, y * horTurnSpeed, 0);
    rigidbody.AddRelativeTorque (y * (-1)*verTurnSpeed * Vector3.forward); // added this
}

I would like to stop the plane spin once the user has released the button. I’m quite sure I’m doing something wrong here :slight_smile:

Thanx in advance.

Try increasing the angularDrag on your rigidbody.

Thanks. Works like a charm.

Wow, these nice forums make me want to ask another question :slight_smile:

I’d like the camera to follow the object but ignore the spin. So you can spin the airplane upside-down, but see the world in normal view.

Should work out of the box if you attach to the camera the SmoothFollowTarget script from the components->scripts menu and select as target parameter in that component your ship. I did this in my little space ship prototype and it works great.

Thanks for your input Martin. I realized later that I was using the wrong camera script oO

I do get some camera twitching due to terrain i think. Tried changing the distance and height, but it still doesnt run smooth when i ascend with my plane.

This is what i managed to do so far. Please note it is a 2-day unity experience.

http://www.colorsoft.hr/air-race.aspx - enjoy!

You probably need to remove the other script your cam was using.

I removed it. Still not so good. Check the 0.0 version, maybe you see what i did wrong.