Home   Help Search Login Register  

Author Topic: 3 Dimensional projectiles  (Read 880 times)

0 Members and 1 Guest are viewing this topic.

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
3 Dimensional projectiles
« on: 09 Feb 2003, 16:39:38 »
Ok I have a script, and its not working!  The idea of the script is that it creates a shell at a position (_Launcher) and "shoots" it as a target (_target).



;Get the name of the target, the launcher, the type of munitions and the flight time

_Target = _This Select 0;
_Launcher = _This Select 1;
_shelltype = _This Select 2;
_FlightTime = _This Select 3;

#Fireone

;Get the difference in X co-ordinate (East/West)

_Xdistance = (Getpos _Target Select 0) - (Getpos _Launcher Select 0);



;Get the difference in Z co-ordinate (North/South)

_Zdistance = (Getpos _Target Select 1) - (Getpos _Launcher Select 1);



;Get the difference in Y co-ordinate (Up/Down)

_Ydistance = (Getpos _Target Select 2) - (Getpos _Launcher Select 2);



;Calculate the planar angle of attack, measured clockwise from the positive X axis

_planarangle = _Zdistance/(tan _Xdistance);



;Create the first projectile round slightly above the launcher.

_shell1 = _shelltype Camcreate [Getpos _Launcher Select 0, Getpos _Launcher Select 1, (Getpos _Launcher Select 2)+1]



;Give the Shell the correct velocity

_Shell1 SetVelocity [_Xdistance/_FlightTime, _Zdistance/_FlightTime, (_Ydistance- (0.5*(-9.8)*(_FlightTime^2)))/_FlightTime ];

~4

Goto "Fireone"


Now the script works at close range.  But over long distances the shells are falling short (very short).  I have a feeling its the Y velocity, but cant get my brain around the correct line.
« Last Edit: 09 Feb 2003, 16:51:12 by [icarus_uk] »

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:3 Dimensional projectiles
« Reply #1 on: 10 Feb 2003, 01:52:26 »
Cmon people, 14 views (15 now) and no replies? Have you all gone sissy?!  :P

I just had a brain fart,  does flashpoint model air resistance?
« Last Edit: 10 Feb 2003, 02:05:32 by [icarus_uk] »

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:3 Dimensional projectiles
« Reply #2 on: 10 Feb 2003, 12:13:54 »
Cmon peeps, this has been up 20 hours!  Heeeeelllllpppppp meeeeee  Im meeellllttttiiinngggg! :P

Ive had another brain fart!

If the position launcher is on the ground, and the target is on a hill 40 metres higher than the target, but also still on the ground, will both their Y co-ordinates be 0 ?
« Last Edit: 10 Feb 2003, 12:32:06 by [icarus_uk] »

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:3 Dimensional projectiles
« Reply #3 on: 10 Feb 2003, 12:41:35 »
i like ur brain farts Icarus  ::)

yes da getpos unitname select 2 - gives alwayz 0 4 men and 4 tanks (im not sure bout da tanks)

u need 2 find da altitude above sea level 4 both (i think ;D)

try dat function and mebe it wil work :wow: ;D

LCD OUT

[edit] - k da thing goes like dat  :o

da getpos unit select 2 alwayz gives high above ground - but if u try it on Tanks (and prooly soldiers and not armored vehicles - but im not sure) it gives less dan 1 alwayz
« Last Edit: 10 Feb 2003, 12:50:03 by LCD »
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Noon416

  • Old Bugger
  • Former Staff
  • ****
Re:3 Dimensional projectiles
« Reply #4 on: 10 Feb 2003, 12:54:59 »
I wouldn't say you need to adjust for "air resistance", so much as just adjusting for gravity alone, which is definitely modelled by the engine.

You'd need to find/create a function to either:
- adjust projectile velocity to scale with the distance to target, or;
- adjust the projectiles firing elevation to compensate for the increased drop over the larger distance.




Hope that helps, as I've just done serious damage to the last remaining brain cells I had ... ;)

"If a man talks in the woods and no woman hears him, is he still wrong?"

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:3 Dimensional projectiles
« Reply #5 on: 10 Feb 2003, 13:48:57 »
As far as I know, Im already doing that.   Using the dynamics exquation;

(Initial Velocity) = (Displacment) - 0.5 * (acc of gravity) * (Flight Time) ^ 2 / (Flight Time)

Using that in each of the 3 axis (in the X and Z the acc due to gravity is 0) should make the projectile land on the target every time,  assuming of course that there is no drag caused by air resistance.

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Re:3 Dimensional projectiles
« Reply #6 on: 10 Feb 2003, 17:52:21 »
Welcome to OFP physics.  There is drag. :P

I couldn't figure it out.  This is as far as I got:

_dx = ((_pos select 0) - (_src select 0))
_dz = ((_pos select 1) - (_src select 1))
_dist = sqrt ((_dx ^ 2) + (_dz ^ 2))

_dir = _dz atan2 _dx
_angle = 20
_muzzle = sqrt (9.8 * _dist / sin (2 * _angle))

_vy = _muzzle * sin _angle
_hyp = _muzzle * cos _angle
_vx = _hyp * cos _dir
_vz = _hyp * sin _dir

_shell = _type createVehicle [_src select 0, _src select 1, 2]
_shell setVelocity [_vx, _vz, _vy]

Doolittle
« Last Edit: 10 Feb 2003, 17:56:41 by Doolittle »

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:3 Dimensional projectiles
« Reply #7 on: 10 Feb 2003, 18:59:36 »
Thats all very frilly.  Mind explaining what the heck it means?

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:3 Dimensional projectiles
« Reply #8 on: 10 Feb 2003, 19:05:41 »
y not just cheat da engine ? ;D

use looped setpos  ;) ;D

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:3 Dimensional projectiles
« Reply #9 on: 10 Feb 2003, 19:12:23 »
cause thats cheating!

Do tank shells still make that whistling noise when they are setpossed?  Either way, Id still like to work out the air resistance.

Doolittle, any help on understanding, and implementing your script there?

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Re:3 Dimensional projectiles
« Reply #10 on: 18 Feb 2003, 22:44:39 »
Actually mine does what you are doing, but you are doing it in a much nicer way.  I think they're both the same.

I have been working on combatting air resistance for a couple days now.  One thing I did that comes CLOSE is to cheat and have a loop with the shell until it explodes, in that loop you set the X and Z velocity to the same initial X and Z over and over.  This removes the DRAG from the horizontal movement, but now still need to "negate" the Y friction.

Doolittle

Offline KTottE

  • Former Staff
  • ****
Re:3 Dimensional projectiles
« Reply #11 on: 19 Feb 2003, 12:26:06 »
This is teh advanced scriptarz, so I moved it here.

I'm way too tired to wrap my head around the maths involved here, but from a quick glance, Doolittle is on to something.
I suggest checking CareyBear's posts over on the official forum, he was working on a script similar to this.
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"