OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Messiah on 04 Feb 2005, 21:55:28

Title: Vehicle reversing?
Post by: Messiah on 04 Feb 2005, 21:55:28
i was wondering if it would be possible to check the direction a vehicle is facing and then check if it was moving in the oposite direction to which it was facing, hence check if it was reversing?

mainly need it for a bit of larger scripting for some things im working on

cheers  :)
Title: Re:Vehicle reversing?
Post by: MachoMan on 04 Feb 2005, 21:59:40
yes that would be possible ...  ;D
Title: Re:Vehicle reversing?
Post by: RujiK on 04 Feb 2005, 22:16:08
Code: [Select]
?(speed VehicleName < 0):hint"Your going backwards!"
Title: Re:Vehicle reversing?
Post by: MachoMan on 04 Feb 2005, 22:28:09
Ok I'll help out ;D

It's easy if you understand vectors, damn I should have payed more attention at school ;D

Ok to the point:

So we have sin & cos in ofp, we have heading, hey we have 3d Vecs wich give us heading and velocity, thats all we need!

As we all know the dir implementation of ofp is kinda simpel, 0 is North, 180 is south. Now we can combine those values to numbers using sin & cos.
Now im gonna get these things wrong, cause I always do:
(I think u can guess what veh means)
Code: [Select]
A = [sin getDir veh, cos getDir veh, 0]
B = getVelocity veh
//Make sure we can get valid results, since we cannot check vertical heading in ofp:
B = [B select 0, B select 1, 0]
Now we are gonna have to normalize B, to do that see here (http://www.ofpec.com/yabbse/index.php?board=27;action=display;threadid=20574).

Now check
Code: [Select]
(A == -B) (which doesnt work in ofp, but I wont have to explain that I think.)
Et voila you a bool which tells you if you are reversing.
Title: Re:Vehicle reversing?
Post by: Triggerhappy on 04 Feb 2005, 22:56:49
...or you could do what rujik said...

 ;D
Title: Re:Vehicle reversing?
Post by: Planck on 04 Feb 2005, 23:10:02
If speed was 0 then the vehicle is stopped........so maybe:

?(speed VehicleName < 0):hint"Your going backwards!"

would be better.


Planck
Title: Re:Vehicle reversing?
Post by: MachoMan on 04 Feb 2005, 23:52:39
Nah my way is better  ;D
Title: Re:Vehicle reversing?
Post by: macguba on 04 Feb 2005, 23:54:18
I imagine a variation would be:-

? (speed VehicleName = i) : hint "You're going sideways..."   ;D ::)
Title: Re:Vehicle reversing?
Post by: THobson on 05 Feb 2005, 00:24:29
Only in complex space I think ;D
Title: Re:Vehicle reversing?
Post by: RujiK on 05 Feb 2005, 06:15:53
If speed was 0 then the vehicle is stopped........so maybe:

?(speed VehicleName < 0):hint"Your going backwards!"

would be better.


Planck

Oh, woops.
Ok post edited, thanks for noticing that.
Title: Re:Vehicle reversing?
Post by: Fragorl on 05 Feb 2005, 07:43:16
Negative speed is one of the most useful concepts in ofp. Makes life so much easier!  ;D
Title: Re:Vehicle reversing?
Post by: Messiah on 05 Feb 2005, 19:59:31
ok... so negative speed works in ofp? awesome...

i'll try both ideas out and see how they work.

cheers  :)
Title: Re:Vehicle reversing?
Post by: Messiah on 05 Feb 2005, 20:04:15
the negative speed one works excellenty... now to try and get it into an addon with an eventhandler.... always fun  :)

cheers guys