Home   Help Search Login Register  

Author Topic: Detecting distances  (Read 1008 times)

0 Members and 1 Guest are viewing this topic.

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Detecting distances
« on: 22 Mar 2004, 15:44:56 »
We have noticed that the BAS motorcycles can get quite a bit of air when going over a hill etc, and that has got some of the Evil Kneivel wannabees thinking about making a competition map to see who can safely jump the farthest.
  Problem is how do I script it to determine how far someone flies?  getpos and distance just don't seem to be able to detect when the bike lands.  Perhaps there is some other way?  I know this is a funky concept but if it will work then some fun "goof around" maps can come from it!

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Detecting distances
« Reply #1 on: 22 Mar 2004, 18:17:43 »
This isn't that hard. Atleast this was done in 5 minutes:

Code: [Select]
_veh = _this

#start
@ (speed _veh > 0)

#speedloop
(driver _veh) sideChat format ["speed:%1 --- altitude:%2",speed _veh,getPos _veh select 2]
~1
? (speed _veh < .5) : goto "start"

; criteria for starting jump distance measuring is 1 meter as height
? ((getPos _veh select 2) < 1) : goto "speedloop"


hint "measuring jump distance"
_startgl = "Logic" camCreate getPos _veh

@ ((getPos _veh select 2) < 1)
_DX = (getpos _startgl select 0) - (getpos _veh select 0)
_DY = (getpos _startgl select 1) - (getpos _veh select 1)
_dist = sqrt ((_DX * _DX) + (_DY * _DY));
deleteVehicle _startgl

(driver _veh) sideChat format ["WEeEeEE! I jumped %1 meters!!!",_dist]

~4

goto "start"

All you need to do is save that as altmonitor.sqs and put:
this exec "altmonitor.sqs"
in any vehicles init. Shouldn't be too hard to poke around either.
« Last Edit: 22 Mar 2004, 18:18:06 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:Detecting distances
« Reply #2 on: 23 Mar 2004, 14:44:04 »
Fantastic!  I figured there would have to be some equations in there, (not my strong suit), but I think I understand what you have done here.  Will definitely try it out.  Thanks again

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Detecting distances
« Reply #3 on: 24 Mar 2004, 00:09:19 »
Just a lil note on that equation: IIRC, it will calculate only the X and Y plain so it won't be very useful for skijumping style situations where you start from a higher altitude and make your jump down. Instead it'll do for ramp jumps on a plain terrain. You can imagine a dot below your bike and the startpoint of the jump at altitude 0 meters; the current equation calculates the distance between those points.

The OFP built in command distance however puts those 2 dots at those 2 points altitudes. So in effect from skijumping you'd get the distance from a dot at say 155 meters and another at 15 meters which is: 140 meters. With that original equation: 0 meters  ;D

So if you aren't satisfied, delete the 3 rows after
Code: [Select]
@ ((getPos _veh select 2) < 1)
_DX = (getpos ....
and replace them with:
_dist = _veh distance _startgl

That way it'll take the Z change into account, I think.
« Last Edit: 24 Mar 2004, 00:11:05 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:Detecting distances
« Reply #4 on: 24 Mar 2004, 16:16:52 »
Thanks, most of the distances I have been measuring are to the same "altitude".  Messing around with the ramp add on and the BAS motorcycles, and the ramp needs to be on a flat surface to work well.  Also trying it with the dodge R/T challenger add on.  Near as I can tell it works just fine.
BTW. haven't tried it in a MP game, but it should work for every player right?

If you're interested in the ramp and challenger add ons:
http://members.cox.net/usi_zombie

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Detecting distances
« Reply #5 on: 24 Mar 2004, 19:41:52 »
I'm quite sure it works in MP since it has only few of those commands in it that might be better off ran on a server, like the distance from a object created and existing only on a server... so it should run on all machines. You could make the hint visible only on the client who is driving atm by:
? (local (driver _veh)) : hint "measuring jump distance"
and stuff like that. The 'speed' sideChat tho can't be localized that way and it might get annoying and it isn't even necessary.

If it doesn't work, sry to say that will be one big mess to get it working.
« Last Edit: 24 Mar 2004, 19:42:16 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:Detecting distances
« Reply #6 on: 24 Mar 2004, 19:54:07 »
actually I changed the line to display the final distance to:
(driver _veh) globalchat format ["%2  jumped %1 meters!!!",_dist, name driver _veh]
and removed the lines about the speed and altitude sidechats and measuring jump distance sidechat, but they are usefull for troubleshooting/testing purposes.

Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:Detecting distances
« Reply #7 on: 31 Mar 2004, 13:38:47 »
We actually have found a problem with this in MP.  I can jump and it tells me 25M for example, but it tells another player I jumped 27.08 and another 23.55.  Why does it not repeat the same distance to all players for 1 single jump?

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Detecting distances
« Reply #8 on: 01 Apr 2004, 17:42:26 »
That is purely the client vs client issue, the different outcome is due to the lag/netcode. All you might need is:
? (local Server) : dist = ...
and the publicVariable "dist". That should do it. The server is always right  :)
« Last Edit: 01 Apr 2004, 17:43:08 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.