• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Math] projectiles

Status
Not open for further replies.
Level 15
Joined
Oct 29, 2012
Messages
1,474
Well if it's a projectile then you'd configure these :

- Starting Height
- Starting Angle
- Starting Acceleration
- Gravity

And you'll have THREE FUNCTIONS :
- Projectile_timedifference = this is the function of time (which is increasing)
- Projectile_XY = this is the function of position
- Projectile_Z = function of height.

Now these are good threads to start with :
Wikipedia Projectile Motion
Trajectory of a projectile
Mathwords Projectile Motion
Projectile's motion in C++
Basic Eqations and parabola path


If it seriously can't be helped, then give me feedback, I will post here a projectile system test map (which I made a long ago) which is fully configurable (needs a little bit of tweaking) and you'll have it as a get-go thing.
 
When making a projectile system, you will find that it is much easier to think in the term of vectors than it is in parabolas. Your projectile will need to have one vector for position (x, y, z) and one for velocity (vx, vy, vz). If you are using vJass, just make a struct for the projectile (will make your life much easier), otherwise use an array for each variable and use some method to find a unique index for each projectile, then use the index to access the array items.

I can totally recommend this tutorial if you are new to linear algebra and vectors.

When storing the Z cooridnate, it is much easier to use the absolute height of the unit, i.e. terrain height + flying height. This way, you can set the fly height to proj_z[proj_id] - GetTerrainZ(proj_x[proj_id], proj_y[proj_id]). In this case, GetTerrainZ is a custom function where create/move a global location at (x,y) and find the terrain height using GetLocationZ(). This way, you never have to really care about terrain height in your calculations. Just check if proj_z < terrain_z to see if it collides with the ground.

Every timer cycle, you subtract your Z velocity with a gravity value, which should be something like 10*TIMER_INTERVAL (where TIMER_INTERVAL is something like 0.03). Then, you add the velocity vector to the position vector. Finally, you move your projectile to the position vector. The resulting movement will be parabolic.

EDIT: You can also multiply your velocity vector with something like 0.98 every cycle if you want to add air resistance. This createas a pretty cool effect. If you want to see a projectile system based on these principles, you can check out SupCom by Bob666, or World Domination by myself.

Hope this was helpful.
 
Status
Not open for further replies.
Top