Warning: include(/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php): failed to open stream: No such file or directory in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Warning: include(): Failed opening '/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php' for inclusion (include_path='.:/usr/local/lib/php') in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Notice: Undefined index: OFPEC in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152
    Home   Help Login Register  

Author Topic: Distance to impact!  (Read 4042 times)

0 Members and 2 Guests are viewing this topic.

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Distance to impact!
« on: 30 Jul 2005, 19:55:38 »
At this http://www.ofpec.com/editors/browse.php?searchopts=&start=75 page there's a Bullettime script and by this I can se the distance form the firing platform, to the impact.

How can I make such a small script that shows the distance just as a hint?  :D

DBR_ONIX

  • Guest
Re:Distance to impact!
« Reply #1 on: 30 Jul 2005, 22:42:45 »
Used fired eventhandler, get the unit position.
Loop untill the bullet is dead, the last postion is where the bullet hits
The use
HINT FORMAT ["%1",_startPos distance _endPic]

To distance it
Sorry it's bit vauge, but it's a start :P
- Ben

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Distance to impact!
« Reply #2 on: 30 Jul 2005, 22:51:36 »
Tnx for the quick reply, but I could use it a bit more detailed...(Like if you had to eksplain it to someone who has'nt scripted before... ;))

Offline Blanco

  • Former Staff
  • ****
Re:Distance to impact!
« Reply #3 on: 02 Aug 2005, 05:15:21 »
Used fired eventhandler, get the unit position.
Loop untill the bullet is dead, the last postion is where the bullet hits
The use
HINT FORMAT ["%1",_startPos distance _endPic]

To distance it
Sorry it's bit vauge, but it's a start :P
- Ben

Sounds like a good method to me, but how can you get the position of a bullet that doesn't exist anymore?

This should work :

- First give the unit an eventhandler

Code: [Select]
this addeventhandler ["fired",{_this exec "bulletdis.sqs"}]
then the script
Code: [Select]
;bulletdis.sqs
_shooter = _this select 0
_ammo = _this select 4

_log = "logic" camcreate getpos _shooter

_bullet = nearestObject[_shooter,_ammo]

_dis = 0
#loop
?isnull _bullet :goto "end"
_dis = _bullet distance _log
~0.001
goto "loop"


#end
player globalchat format ["You've fired %1m far",_dis]
deletevehicle _log
exit

Not tested :p
The logic is not really needed but what if the unit moves?
The difference won't be that much, but it's more precisly imo.
BTW, I wont show it in hint... When you fire in burst or auto mode you will suffer from permanent braindamage  ;D

PS : EH fired rarely catch sabots (or other shells) or machinegun bullets, they are too fast when they leave the barrel.






« Last Edit: 02 Aug 2005, 12:33:51 by Blanco »
Search or search or search before you ask.

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Distance to impact!
« Reply #4 on: 02 Aug 2005, 14:14:08 »
Tnx for the script. I've changed it to Hint format thoug. It's needed for a static single shooting weaponplatform. I've fired OWP BM-21 in an angle of 45 degrees and got a distance of 632.828 m long before the rocket impacted with the ground. I tried this a few times with the same angle but got different distances. The script seems a little to inaccurate and unreliable...

What I need is a precise distance every time when the rocket impacts - not before and not after...

 :) ;) :D ;D

Offline Blanco

  • Former Staff
  • ****
Re:Distance to impact!
« Reply #5 on: 02 Aug 2005, 14:34:54 »
Quote
...long before the rocket impacted with the ground

That's weird, this means the condition isnull _bullet is unreliable...
I know the model of missile disspear when it goes faster than 450km/h, I saw that when I attached a camera to the projectile.
Maybe then i?snull _bullet kicks in...?
Maybe the moment the bullet disappears isn't the moment of impact.
Maybe try another condition like :

Code: [Select]
?speed _bullet <= 0 : goto "end"
And see of it give you different results.
Or make the loop constant...
Ask the ECP guys, they should know the position of impact...they need it to create the explosions and watersplashes...
« Last Edit: 02 Aug 2005, 14:56:16 by Blanco »
Search or search or search before you ask.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Distance to impact!
« Reply #6 on: 02 Aug 2005, 16:18:21 »
Quote
I know the model of missile disspear when it goes faster than 450km/h
I doubt this very much...
More likely the lifetime of the missile ran out since OFP missiles live something like 12 seconds... Bullets live about 3 seconds...
'Cannon' shells live like 20 secs or so and bombs 30... (don't quote me on those but they are something on those lines...)

And, I think some of MCAR rockets go faster than 450 km/h...
(ok, don't quote me on that either ;D ::) )

The lifetime running out will also cause !alive or isNull checks to return true...

Quote
PS : EH fired rarely catch sabots (or other shells) or machinegun bullets, they are too fast when they leave the barrel.
True, if you use a script or a function to 'catch' the bullet (awh, how many times I've been trough this here already ::) )...
If you catch the bullet straight in the fired eventhandler before passing it into a script you will catch any bullet even on 1 FPS game (well, this 1 FPS thing applies at least when the fired event is defined in the config of a vehicle..)...

Code: [Select]
this addEventHandler ["fired",{_theBullet = nearestObject [_this select 0,_this select 4]; [_theBullet,_this] exec "thecode.sqs"}]or
Code: [Select]
this addEventHandler ["fired",{[(nearestObject [_this select 0,_this select 4])] exec "thecode.sqs"}]or something similar...

Quote
What I need is a precise distance every time when the rocket impacts - not before and not after...
You just need to do a simple check wether the the looping script has ran long enough for the rocket to be ran out it's 'life' and tell the script not to react to it anymore, or something...
Code: [Select]
_time > 11: exit
Quote
The script seems a little to inaccurate and unreliable...
This might be due to the delay in the loop..

Try this instead:
Code: [Select]
#loop
?isnull _bullet :goto "end"
_dis = _bullet distance _log
@true
goto "loop"
(no guarantees on the syntax)
Or don't use a delay at all (this may cause OFP to 'drown'...)

Just throwing ideas...


Also, I didn't find any OWP BM-21 addons with my very quickie search so I don't know whether they have scripted the cannon so that the fired rocket (or what ever) is substitued with a new one periodicly to get longer firing distances (surpassing those life time limits..)..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Distance to impact!
« Reply #7 on: 02 Aug 2005, 20:40:01 »

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Distance to impact!
« Reply #8 on: 10 Aug 2005, 20:49:39 »
#Bump
Plenty of reviewed ArmA missions for you to play

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Distance to impact!
« Reply #9 on: 18 Aug 2005, 12:52:26 »
 :hmm:

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Distance to impact!
« Reply #10 on: 18 Aug 2005, 13:15:10 »
Code: [Select]
_bullet = nearestObject[_shooter,_ammo] This line seems to be the problem. I've tried to replace _shooter with the name of the weaponplatform, and _ammo with the name of the ammo the platform shoots with...(owp_bm_rocket), but it gives me an error...

the error says: 0 elements provided, 3 expected

Bluelikeu

  • Guest
Re:Distance to impact!
« Reply #11 on: 19 Aug 2005, 00:00:45 »
just as a similar question, how would one calculate the time it would take an object to hit a location. For example a mortar shell that is fired up in the air. I want to be able to calculate when and where the shell is going to hit. Is there a possible solution?

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Distance to impact!
« Reply #12 on: 19 Aug 2005, 11:02:17 »
Well assuming the location is on the same vertical plain as the firing object (same height above sea level).  The formula is:

Time to impact =( 2*V*Sin (theta))/9.8

where V is the velocity of the missile  and theta is the angle of elevation of the shot.
After the missile has been fired you could get its height twice separated by a short time interval to derive the angle of elevation.

It gets a bit more complicated if the shooter and the target are not at the same height above sea level.  Then if my very rusty maths is correct it is something like:

Time = (V*Sin (theta) +- ((V*Sin(theta))^2 - 2*9.8*S)^0.5)/9.8

Where S = the difference in the height above sea level of the target and the gun.
+- means there are two possible solutions one where you use the + and one where you use the -.  One may not be valid.

Hope this helps ::)

« Last Edit: 18 Sep 2005, 07:02:55 by THobson »

Bluelikeu

  • Guest
Re:Distance to impact!
« Reply #13 on: 15 Sep 2005, 21:46:35 »
s = displacement
t = time
u = initial speed
a = acceleration

This is the formula for calculating displacement

s = ut + 0.5at^2

as Thobson said before, one is going to need to use the quadratic formula to find the values for t.


Here's just an example I'm making:

t = time of interest
u = initial speed of the object
v = its final velocity
a = -9.8
s = total displacement from starting position
so,
We're trying to find the life span of this object, or t.
given values:
u = 12ms-1
v = 30ms-1
a = -9.8ms-2
s = 200m

this is our equation so far:
200 = 12*t + 0.5(-9.8)t^2

converting to quadratic equation :
0 = (-0.49)t^2 + 12t - 200

using quadratic formula to find the values for t:

formula:
t = (-b +- sqrt(b^2 - 4ac))/(2a)

t = (-12 +- sqrt(12^2 - 4*-0.49*-200))/(9.8)

do the math and the two possible values for t are known. If one of them is negative, then take the one that is positive. The value for t then tells us at what time all of those variables are true. This might be useful in some cases when you need to calculate other properties.

there may be something wrong, but i think this is right.

Also, almost forgot something very important that you guys might like.
The maximum height of the object:
This is how high the object reached during its life span.
in this case t = total time the object was alive
0 = u + at

this will allow you to get the maximum height of the object, this is good if you wanted to calculate wheather or not something can shoot high enough to reach the target, or whatever. Just bsing here.

Anyway, hope this is right and helps in someway.

Thanks Thobson for inspiring me to learn physics
Bluelikeu

Offline paddy

  • Contributing Member
  • **
  • Llama whipping good
Re:Distance to impact!
« Reply #14 on: 18 Sep 2005, 00:48:54 »
you have attempted to put the quadratic formula into OFP, an accomplishment to be proud of .. and thats maths, not physics.

plus, ts not true physics unless either it contains stuff that hasnt been proved, or science doesn't have a friggin clue wots goin on.  Thats REAL physics!!!  :D
« Last Edit: 18 Sep 2005, 00:49:37 by paddy »