Jump to content
Sign in to follow this  
pexmo

limit and set speed of a vehicle?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Mission editing questions belong in the mission editing forum, please look to ensure you're posting in the correct place.

Moving.

Share this post


Link to post
Share on other sites

But hey, wouldn't it be possible to check if a car is going at a certain speed and then if it'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

?(velocity car1 >5):goto "slowdown"

~0.01

goto "speedcheck"

#slowdown

car1 setVelocity [0,5,0]

~0.01

goto "speedcheck"

Not sure about it, and I don't know if there's such a command as getVelocity. Can'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's facing.

EDIT: getVelocity doesn't exist, use velocity instead.

EDIT2: Bah, some typos.

Share this post


Link to post
Share on other sites

No such command as getvelocity but speed will give you a unit's speed in km/h.

So yes, Dynamite_cow, you'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'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 > 5: _unit setVelocity [3*(sin(getDir _unit)),3*(cos(getDir _unit)),1]

?endspeedlimit || !canmove _unit: exit

~0.05

goto "loop"

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

Quote[/b] ]How do i set a movement speed for a soldier...

Due to how setvelocity works it'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 biggrin_o.gif

Share this post


Link to post
Share on other sites
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 biggrin_o.gif

I don't think so. If the only thing is that the soldier must be off the ground, couldn't you just raise him like 1cm so that it wouldn't even be really noticeable, and then setVelocity him? At least for jumping directly upwards it'd work fine I think.

Or if it'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 [(getpos this select 0), (getpos this select 1), 0.1]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.2]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.3]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.4]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.5]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.6]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.7]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.8]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 0.9]

~0.1

_unit setpos [(getpos this select 0), (getpos this select 1), 1]

~0.1

_unit setVelocity [0,0,50]

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'd be properly noticeable) and then jumping upwards at 50km/h. Propably still looks quite strange, though.

Share this post


Link to post
Share on other sites

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 (!(Alive _Vehicle) Or STOPSPEEDLIMIT) Then {goto "Exit"} Else {If (!(IsEngineOn _Vehicle) Or (IsNull (Driver _Vehicle))) Then {goto "L"}}

@Call {_Vel=Velocity _Vehicle; If ((Speed _Vehicle)>_MaxSpd) Then {_Vehicle SetVelocity [(_Vel Select 0)*_Factor,(_Vel Select 1)*_Factor,_Vel Select 2]};  !((Alive _Vehicle) Or (IsEngineOn _Vehicle)) Or (IsNull (Driver _Vehicle)) Or STOPSPEEDLIMIT}

goto "L"

#Exit

Share this post


Link to post
Share on other sites

So.. setvelocity doesnt really work? confused_o.gif .

i.e. you cant setvelocity of a vehical to a value in km/h.

Never tried it before...

Share this post


Link to post
Share on other sites

setVelocity accepts m/s, not Km/h.

setVelocity set INSTANTANEOUS (not CONSTANT) velocity of any movable object.

Share this post


Link to post
Share on other sites
Quote[/b] ]So.. setvelocity doesnt really work?

No, not with infantry. Unless, as stated above, the guy is not touching the ground. Anything else is ok.

Most of the time, you probably don't need it with infantry. As they "should" all move at the same speed, plus I think you have more control over a units speed using waypoint settings and combat mode (safe,combat e.t.c), than you do with different types of vehicles?

Share this post


Link to post
Share on other sites

m/s = ? (meters per second?)

Im not interested in having infantry running around at a specified speed, even less if their running above ground level, maybe above water tounge2.gif . Just curious about setvelocity and its use with vehicles, the velocity settings in WP's seem more adequate and suficient. Thanks for your replies smile_o.gif .

Share this post


Link to post
Share on other sites

You can set the speed of a vehicle using setvelocity in kmh.

Formula somewheres in these forums by the uber Denoir eons ago

Share this post


Link to post
Share on other sites

do you now if a unit got a flag how to return it ti the flag pole

Share this post


Link to post
Share on other sites
You can set the speed of a vehicle using setvelocity in kmh.

The Speed command returns kmh, the velocity command returns m\s.

The script I posted uses the Speed command to regulate the vehicles speed, the velocity command is used to reduce the speed when it exceeds the max speed in kmh, that you define.

Quote[/b] ]Formula somewheres in these forums by the uber Denoir eons ago

But if you want the formula for converting m\s to kmh, just search with google, it's regular maths:

Quote[/b] ]1 kmh ; 0.2778 m·s (approximately)

So 5 kmh would be:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">5 * 0.2778 = 1.389 m\s

But why add all those extra script commands and trigonometry? You only need to do that, when your forcing an object that can't move on it's own.

Share this post


Link to post
Share on other sites
do you now if a unit got a flag how to return it ti the flag pole

Could you stop raping this thread with off topic posts confused_o.gif , i dont mean to be rude but you are asking for stuff that has been answered thousands of times already and can be easily found using the search feature. There is also a pinned thread with aswers to some of the most comun questions smile_o.gif .

Share this post


Link to post
Share on other sites
do you now if a unit got a flag how to return it ti the flag pole

Please do not take threads off-topic with irrelevant questions.

If you have a question which has not been answered before, make a new thread.

Using the Search function in your quest will be helpful thumbs-up.gif

Share this post


Link to post
Share on other sites
Could you stop raping this thread with off topic posts

There's no need for such a statement.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×