OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Mad Pup on 15 Feb 2012, 21:42:10

Title: [SOLVED]Vehicle, slow to stop?
Post by: Mad Pup on 15 Feb 2012, 21:42:10
Is there a way to get a car to slowly come to a stop, say over 10 seconds, through a script? (How long it takes doesn't matter).

THANKS!

- Mad Pup
Title: Re: Vehicle, slow to stop?
Post by: Raptorsaurus on 24 Feb 2012, 00:26:45
You could do it with a script using the setVelocity command. I made a function called "setSpeed.sqf" that simplifies the scripting for manipulating vehicle speeds. I will make a demo for you once I have access to my computer (later this evening). I do need to know, do you want the parameters to be based on the deceleration rate, the distance traveled or a position? For example, do you want the vehicle to come to a stop just as it reaches another object or unit, or do you just want it to slow at a given rate or do you want it to cover a certain distance before it stops?
Title: Re: Vehicle, slow to stop?
Post by: Mad Pup on 25 Feb 2012, 16:00:06
Basically, you're chasing the car. And if you come within say 10 feets of the back of the car, it will cause the car to slow down, slowly to  a stop.... I'm currently using

Code: [Select]
car1 setfuel 0.0
car2 setfuel 0.0

car1 being the car you're chasing.
car2 being you're car.

but that's kind of unrealistic. Just stoping....

Again, thanks for all the responses!

-Mad Pup
Title: Re: Vehicle, slow to stop?
Post by: STiT/LK on 25 Feb 2012, 21:10:35
Try with this script. When you're within a given distance (5 meters, but you can modifiy according to your needs) the vehicle will slow down and then completely stop.  :)

To execute it, put this in some init field: [car1,car2] exec "slowDown.sqs" and play as car2.

slowDown.sqs
Code: [Select]
_veh = _this select 0
_cha = _this select 1

_veh setSpeedMode "FULL"
_veh setBehaviour "DANGER"
_veh lock true

#chase
@(_cha distance _veh) < 5
goto "stop"

#stop
_veh setSpeedMode "LIMITED"
~1.5+random(0.5)
_veh action ["ENGINE OFF"]
~1.5+random(0.2)
?isEngineOn _veh : _veh action ["ENGINE OFF"]
_veh stop true
exit
Title: Re: Vehicle, slow to stop?
Post by: Raptorsaurus on 29 Feb 2012, 19:40:27
You could try this:

Script named "stopCar.sqs"

Code: [Select]
_car1 = _this select 0
_car2 = _this select 1
_dis = _this select 2

@ _car1 distance _car2 < _dis || {canMove _x} count [_car1, _car2] < 2 || ! isEngineOn _car1
;the script waits until one of the above conditions is true

? {canMove _x} count [_car1, _car2] < 2 || ! isEngineOn _car1 : exit
;if _car1 turns off his engine (like being out of fuel or engine is damaged) or either car is damaged to the point of not being able to move there is no point in the script continuing

_car1 lockWP true
;this locks the current waypoint of the car being chased (he will not resume following waypoints until the command "_car1 lockWP false" is used.

_car1 move getPos _car1
;this makes the car stop because he is already at his present location

@ speed _car1 < .1
;script waits until _car1 slows to almost a complete stop

_car1 setFuel 0
;sets the fuel of _car1 to zero so he cannot drive away

exit

Call this script using something like:
Code: [Select]
[badcar, policeCar, 10] exec "stopCar.sqs"
You would be the in the policeCar and the other car would be the one you are chasing (the badcar), but use whatever names you want for the two cars. The distance for the car to stop is 10, but you can change this also.
Title: Re: Vehicle, slow to stop?
Post by: Mad Pup on 01 Mar 2012, 01:07:31
Looks good Raptorsaurus. I'll test both the scripts out tonight!!! I'll let you both know how it goes! I might even let you guys beta test the mission!  :blink:
 ;)

-Mad Pup