x


Banking and momentum

Hi. I recently got a script for an aeroplane, and I need to know how to make it bank.

var maxTorque : float = 10.0f;
var forwardForce : float = 10.0f;

var currentTorqueHor : float = 0.0f;
var currentTorqueVer : float = 0.0f;

function Update()
{
    currentTorqueHor = maxTorque * Input.GetAxis("Horizontal"); 
    currentTorqueVer = maxTorque * Input.GetAxis("Vertical");
    }

function FixedUpdate()
{   
    rigidbody.AddForce(transform.forward * forwardForce);
    rigidbody.AddRelativeTorque(currentTorqueVer, 0.0f, -currentTorqueHor);
}

This script doesn't let me bank. When I rotate a bit I have to go up to move in that direction. I've seen people do it before and it works very well. Also, I have a problem with momentum. When I change direction, it takes a while for my momentum to recede. So, if I turn the opposite direction, I will fly in backwards while slowing down until it stops, and then accelerate forward. Anyone know how to change this?

more ▼

asked Apr 09 '11 at 01:05 AM

Max 4 gravatar image

Max 4
254 60 64 71

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
//replace with this script.
//under edit-projectsettings-inputs set the axis you want
// to use to bank and call it "Bank" .
var maxTorque : float = 10.0f;
var forwardForce : float = 10.0f;

var currentTorqueHor : float = 0.0f;
var currentTorqueVer : float = 0.0f;
var currentTorqueBank : float = 0.0f;

function Update()
{
    currentTorqueHor = maxTorque * Input.GetAxis("Horizontal"); 
    currentTorqueVer = maxTorque * Input.GetAxis("Vertical");
    currentTorqueBank = maxTorque * Input.GetAxis("Bank");
    }

function FixedUpdate()
{   
    rigidbody.AddForce(transform.forward * forwardForce);
    rigidbody.AddRelativeTorque(currentTorqueVer,currentTorqueBank, -currentTorqueHor);
}
more ▼

answered Apr 09 '11 at 11:18 PM

creative72 gravatar image

creative72
143 5 5 14

Thanks! Now I need to find out how to remove momentum.

Apr 10 '11 at 11:43 PM Max 4
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2244
x68
x24

asked: Apr 09 '11 at 01:05 AM

Seen: 812 times

Last Updated: Apr 09 '11 at 01:05 AM