# Thread: limit and set speed of a vehicle?

1. How do i set a movement speed for a soldier or a vehicle?

I want to have my convoy set to moving at a set speed. Limited speed is too fast. how do i do this?

I have a separate driver unit set to careless and a separate gunner set to aware. I want to have the driver unit moving a set speed lower then limited speed mode.

2. I have seen missions in wich cars drove very slow (without driver even&#33, so all I can say you is that it IS possible... but I dont know how.

3. hmm i think there is a way to setspeed, but it will need a loop, cause ai always wanna go faster and you need to slow it down.

the other way is
car setvelocity [5,0,0] [west/east, north/south, height]
car setdir 90

you will need to correct the direction at turns and also the speed when you move direction, it will be a nightmare. lol. try ofpec the forums are now open there and all the codies have been without questions for somemonths :0.

4. You could try tricking around with a mixture of limited speed and behaviour "STEALTH" - combatmode "RED" or something like that. AFAIK behaviour and combatmode have an impact on the speed of the vehicles, just play around.

5. Mission editing questions belong in the mission editing forum, please look to ensure you&#39;re posting in the correct place.

Moving.

6. But hey, wouldn&#39;t it be possible to check if a car is going at a certain speed and then if it&#39;s over x then slow it down? So, say, you want the car named "car1" to drive at 5km/h directly to the north.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
#speedcheck
?&#40;velocity car1 &#62;5&#41;&#58;goto &#34;slowdown&#34;
~0.01
goto &#34;speedcheck&#34;
#slowdown
car1 setVelocity &#91;0,5,0&#93;
~0.01
goto &#34;speedcheck&#34;[/QUOTE]

Not sure about it, and I don&#39;t know if there&#39;s such a command as getVelocity. Can&#39;t be bothered to check, and also this script only makes the car go directly to the north, someone with more scripting experience can tell how to make the car go to the direction it&#39;s facing.

EDIT: getVelocity doesn&#39;t exist, use velocity instead.
EDIT2: Bah, some typos.

7. No such command as getvelocity but speed will give you a unit&#39;s speed in km/h.

So yes, Dynamite_cow, you&#39;re basically right it should be possible. However, it will require a bit more advanced mathematics to get check the direction the car is heading in x,y,z and then applying the setvelocity command accordingly.

Back when the setvelocity command was introduced with 1.75 (or was it 1.85) I made an ugly afterburner script and tested it with a moped.. maybe I could dig it up and modify a bit.. let&#39;s see..

[mytank] exec "speedlimit.sqs"
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
_unit = _this select 0

#loop
?speed _unit &#62; 5&#58; _unit setVelocity &#91;3*&#40;sin&#40;getDir _unit&#41;&#41;,3*&#40;cos&#40;getDir _unit&#41;&#41;,1&#93;
?endspeedlimit &#124;&#124; &#33;canmove _unit&#58; exit
~0.05
goto &#34;loop&#34;
[/QUOTE]

The above is not tested, so it may not work or at best you need to fiddle with the values.

Originally Posted by [b
Quote[/b] ]How do i set a movement speed for a soldier...
Due to how setvelocity works it&#39;s not possible to apply it to a soldier unit (or other units except vehicles and objects) unless the unit is not on the ground. In other words, if your soldier is 1 meter above ground then you can use setvelocity on him, but if he stands on ground the setvelocity will have no effect. You could of course raise the soldier with the setpos command a little bit off the ground before applying the setvelocity but I figure that would look rather nasty

8. Originally Posted by (Artak @ June 29 2006,12:31)
You could of course raise the soldier with the setpos command a little bit off the ground before applying the setvelocity but I figure that would look rather nasty
I don&#39;t think so. If the only thing is that the soldier must be off the ground, couldn&#39;t you just raise him like 1cm so that it wouldn&#39;t even be really noticeable, and then setVelocity him? At least for jumping directly upwards it&#39;d work fine I think.

Or if it&#39;s gotta be, say, 1 meter above the ground, one may use a script like this:
player exec "upupandaway.sqs"
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
_unit = this select 0
#loop
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.1&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.2&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.3&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.4&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.5&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.6&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.7&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.8&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 0.9&#93;
~0.1
_unit setpos &#91;&#40;getpos this select 0&#41;, &#40;getpos this select 1&#41;, 1&#93;
~0.1
_unit setVelocity &#91;0,0,50&#93;[/QUOTE]

Thus, causing unit to raise to 1 meter of height in 1 second (the unit does drop a bit during the 0.1 seconds, but not that much it&#39;d be properly noticeable) and then jumping upwards at 50km/h. Propably still looks quite strange, though.

9. You can restrict the speed of a vehicle using this script. Just call it for each vehicle, passing the speed as a parameter. When you want to release the vehicles in your convoy, just set STOPSPEEDLIMIT=True. As for soldiers, perhaps grouping them with any of the vehicles will force them to follow at the correct speed?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Vehicle=_This Select 0
_MaxSpd=_This Select 1

_Factor=0.9

#L

~1

If &#40;&#33;&#40;Alive _Vehicle&#41; Or STOPSPEEDLIMIT&#41; Then {goto &#34;Exit&#34;} Else {If &#40;&#33;&#40;IsEngineOn _Vehicle&#41; Or &#40;IsNull &#40;Driver _Vehicle&#41;&#41;&#41; Then {goto &#34;L&#34;}}

@Call {_Vel=Velocity _Vehicle&#59; If &#40;&#40;Speed _Vehicle&#41;&#62;_MaxSpd&#41; Then {_Vehicle SetVelocity &#91;&#40;_Vel Select 0&#41;*_Factor,&#40;_Vel Select 1&#41;*_Factor,_Vel Select 2&#93;}&#59; ***&#33;&#40;&#40;Alive _Vehicle&#41; Or &#40;IsEngineOn _Vehicle&#41;&#41; Or &#40;IsNull &#40;Driver _Vehicle&#41;&#41; Or STOPSPEEDLIMIT}

goto &#34;L&#34;

#Exit[/QUOTE]

10. So.. setvelocity doesnt really work? .
i.e. you cant setvelocity of a vehical to a value in km/h.
Never tried it before...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•