x


how to clamp acceleration?

Hi guys, I need to give my vehicle an automatic acceleration up to a certain point, im pretty sure i need to use Mathf.Clamp but i'm not sure how to script it properly. The player doesnt control the speed, but my script currently has a user input to make it accelerate.

function FixedUpdate () {
//query input axes if necessarry
if(queryUserInput)
{
    brake = Mathf.Clamp01(-Input.GetAxis("Vertical"));
    //handbrake = Input.GetButton("Jump")?1.0:0.0;
    //steer = Input.GetAxis("Horizontal");
    motor = Mathf.Clamp01(Input.GetAxis("Vertical"));

} else { motor = 0; //steer = 0; brake = 0; //handbrake = 0; }

I need to change this motor into an automatic motor that never goes above a certain speed. If someone could help me out with the basic script I'll of course edit the values myself, just need a start. Cheers - monster.

more ▼

asked Feb 13 '12 at 10:15 PM

ratboy gravatar image

ratboy
41 18 21 22

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

1 answer: sort voted first
more ▼

answered Apr 09 '12 at 05:34 AM

blacksnow gravatar image

blacksnow
21 1

(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:

x97
x32
x25
x24

asked: Feb 13 '12 at 10:15 PM

Seen: 583 times

Last Updated: Apr 09 '12 at 05:34 AM