# Limiting a vehicles speed?

## Recommended Posts

Hey guys, I'm pretty new to ArmA2 mission editing & scripting. I was wondering if someone could teach me how to limit the speed of a vehicle. I checked the wiki and I just had problems doing it myself. I also used the search function on the forums to find a solution, but no dice. Thanks in advanced. :bounce3:

##### Share on other sites

Put this in the init field of the vehicle you want to limit

`this forceSpeed 5.5;`

Obviously you could change the speed to whatever you want. 5.5 is approximately the speed at which infantry run.

##### Share on other sites

That doesn't have any effect at all sadly. :(

##### Share on other sites

I tested it and it works for me. You sure you put it in the right field? If you did, try changing the speed to 1 to make it's effects more obvious and see if that works.

##### Share on other sites

Still not working, am I doing something wrong? Also, I tried 1, still a no go.

##### Share on other sites

Oh you're trying it for a car you drive? The forceSpeed command only works with AI vehicles. I don't know how to do what you're asking, sorry.

##### Share on other sites

You could run a loop that checks the speed and reduces it to your wanted maximum every second or so

##### Share on other sites
You could run a loop that checks the speed and reduces it to your wanted maximum every second or so

That is what I've been trying to do, but I can't seem to get it right.

_governator = 1;

while { _governator == 1 } do { this limitSpeed 20; };

Also tried force speed. Just not working.

##### Share on other sites

Here's a script that appears to work. I accept no responsiblity for the math in this, I suck at math, it's borrowed from the biki. :)

Put this in the vehicles init field, setting the speed to what you want.

`null = [this, 60] execVM "speedlimit.sqf";`

Then this is the script:

```//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: kylania
//////////////////////////////////////////////////////////////////

// Call this with the following line in the init field of the vehicle.
// this = object to slow.
// 60 = max speed for vehicle.
//
// null = [this, 60] execVM "speedlimit.sqf";

// Pull the object and speed from the execVM.
_vehicle = _this select 0;
_maxspeed = _this select 1;

// Figure current speed.
_curspeed = speed _vehicle;

// If we're going to fast...
if (_curspeed > _maxspeed) then {

// Grab the current velocity and direction of the vehicle.
_vel = velocity _vehicle;
_dir = direction _vehicle;

// Limit it's to bring it back down to the max amount.
_speed = _curspeed - _maxspeed;

// This is math I don't understand, grabbed it from the biki. :)
_vehicle setVelocity [(_vel select 0)-(sin _dir*_speed),(_vel select 1)- (cos _dir*_speed),(_vel select 2)];

}; // End of if

// Sleep tenth of a second, this might be too much processing.  I dunno, slower and the ride get jerkier though.
sleep 0.1;

// Call the script again.
_null = [_vehicle, _maxspeed] execVM "speedlimit.sqf";```

• 1

##### Share on other sites

Kylania, an less math-intensive way would be:

`_vehicle setVelocity [(_vel select 0)/curspeed * maxspeed,(_vel select 1)/curspeed * maxspeed,(_vel select 2)/curspeed * maxspeed];`

• 1

##### Share on other sites

Do you guys can help me. I would like to integrate a script into my mission with which i can limit the speed of a given ground vehicle.

The vehicle is either controlled by squad AI or by the player.

For example: If you press a given key when you driving, or giving a command to an AI driver of a squadmember the limit of the vehicle is set to a certain number.

When you press again, the speed limiter is off.

I have no scripting skills at all, so this makes it quiet difficult for me though.

Tried to look at the scripts of AGM and ACE but they do not quite help me.

I think if one has more clue than i, it is not a big deal.

Cheers

Skanda