OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: RobinHansenDK on 30 Jul 2005, 19:55:38
-
At this http://www.ofpec.com/editors/browse.php?searchopts=&start=75 (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
-
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
-
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... ;))
-
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
this addeventhandler ["fired",{_this exec "bulletdis.sqs"}]
then the script
;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.
-
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
-
...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 :
?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...
-
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...
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..)...
this addEventHandler ["fired",{_theBullet = nearestObject [_this select 0,_this select 4]; [_theBullet,_this] exec "thecode.sqs"}]or
this addEventHandler ["fired",{[(nearestObject [_this select 0,_this select 4])] exec "thecode.sqs"}]or something similar...
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...
_time > 11: exit
The script seems a little to inaccurate and unreliable...
This might be due to the delay in the loop..
Try this instead:
#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..)..
-
Here U go...
BM-21 http://ofp.gamezone.cz/index.php?showthis=6330 (http://ofp.gamezone.cz/index.php?showthis=6330)
-
#Bump
-
:hmm:
-
_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
-
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?
-
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 ::)
-
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
-
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
-
Kinematics. Smells like physics to me!
Anyhow, I hope you have success in this respect; the only times I've tried to use physics to solve problems in ofp, such as points of impact, the damn random element always gets me, ie a shell doesnt land in the same place twice when created and setvelocity'd at the same spot twice... and the whole using script to time things always causes problems. I gave up.
-
What is physics? This could get deep and off topic pretty quickly, so I won't start even though I have a lot to say on the subject.
Bluelikeu: Physics or maths I am glad you felt inspired. The formula you use (S = ...) is indeed the one I used, there are a couple of comments I would make for the sake of clarity:
u = initial speed of the object
Should read:
u = initial vertical velocity of the object
Two points here:
1. Any horizontal movement is irrelevant to the calculation. That is why my formula uses:
u*sin(angle of elevation) where u is the initial velocity of the object. (incidentally u*cos (angle of elevation) will give the horizontal velocity of the object)
2. It is still a velocity not a speed. That is, its direction is important. Imagine the shooter is on top of a hill firing downwards u would then need to be represented by a negative number in your formula.
-
Tnx for all the replies...I'm glad that a lot of people actually shows interrest in my problem. I don't have enougt time ATM due to work and studies so - can someone make the script for me? ;)