Home   Help Search Login Register  

Author Topic: Proxy Rifle Fire From a Rectangle Area  (Read 1070 times)

0 Members and 1 Guest are viewing this topic.

PBrain

  • Guest
Proxy Rifle Fire From a Rectangle Area
« on: 16 Aug 2006, 02:15:43 »
This is a tough script for me but someone out there may have the answer.

Scenario: Rifle fire being created from a user-defined area in the shape of a rectangle that can work with the angle to fire at
                a target.

Problems: -Finding the right calculations needed so the user defines the x and y values of the area as well as the angle so
                  the bullet spawning area can be on an angle and still work. This would be formed around an bullet spawning
                  area object.
                 -Getting the angle of the bullets spawning area to the target so that angle would make the bullet spawning area
                  object face toward the target.
                 -Using the recently acquired angle to make the bullets fly from the bullet spawning area toward the target


Bonus points if you can also come up with a calculation to make the bullets fly up or down at a certain rate depending on the height difference between the bullet spawning area and the target.
« Last Edit: 16 Aug 2006, 02:31:31 by Shane Fair »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Proxy Rifle Fire From a Rectangle Area
« Reply #1 on: 22 Aug 2006, 20:36:52 »
You should perhaps describe what exactly you want this script to do.  Your present description does not entirely make sense.  If you are defining a rectangular area, is the angle you describe simple to rotate the rectangle?  It seems to me what you want to do is:
Define a source volume and a target volume.  A bullet is created at a random point inside the source volume, and sent flying at high velocity to a random position within target volume. 

At the heart of the matter is how to calculate the direction vector from source to target.  To do this you calculate the difference in position to make a vector, divide the vector by its length to give it a unit length, and then multiply by the desired bullet velocity. I have no idea what the bullet velocities in OFP are, but I'll make it 300m/s.
i.e.
Code: [Select]
_bulletvelocity = 300
_dx = (_pos_target select 0) - (_pos_source select 0)
_dy = (_pos_target select 1) - (_pos_source select 1)
_dz = (_pos_target select 2) - (_pos_source select 2)
_length = sqrt(_dx*_dx + _dy*_dy + _dz*_dz)
_velocity = [_dx/_length*_bulletvelocity, _dy/_length*_bulletvelocity, _dz/_length*_bulletvelocity]

Also, try searching the forums for covering fire or suppressive fire or camcreate bullet

This should get you started  :cool2:
« Last Edit: 22 Aug 2006, 21:18:25 by Mr.Peanut »
urp!

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re: Proxy Rifle Fire From a Rectangle Area
« Reply #2 on: 23 Aug 2006, 18:33:19 »
I made two functions that can help you. The first function, ObjDirAngtoObj.sqf, finds the relative angle and direction from an object to another object. The direction and angle is relative to the facing direction of the first object.  The second function, AngDirMagtoVel.sqf, yeilds the velocity vectors required to project an object (in your case a camcreated bullet) in a specified direction and angle relative to the object at a specified magnitude (speed in m/s). You can use these two functions in a script to accomplish what you desire.
« Last Edit: 24 Aug 2006, 00:22:40 by Raptorsaurus »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Proxy Rifle Fire From a Rectangle Area
« Reply #3 on: 23 Aug 2006, 20:36:43 »
Ah yes, I see my code is wrong because _dz does not take terrain into account. However, if it did, it would be correct, and take a lot fewer ops.  Of course, with attaching such, this is all just hot air on my part.
« Last Edit: 24 Aug 2006, 15:41:30 by Mr.Peanut »
urp!