• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Math Problem: Orbiting Missile

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
Hi all.

I want to add a feature to my missile system that allows me to make a missile fly around the target.
However I cannot simply make it move to an offset of the target with a certain difference in degree every 0.03 seconds but I want it to move using a movement speed variable on the missile.

I also want the missile to instead of forcing it to an offset of the target, be moving towards that offset, so if the unit is faster than the missile, then the missile would fall behind.

The maths must be able to make the missile move around the right side of the unit, or around the left side of the unit, or around either side (best one out of the current position of the missile).

I am a bit lost in how to approach this thing so if anyone has any ideas, then please share them.
 
Level 11
Joined
Jan 23, 2015
Messages
788
RJnuCCY.png


Need to find the red point first, you have the hypotenuse (c) and the radius (a), but you just have the angle of 90, im bad at math, but i think you can solve this using sine/cosine/tangent whatsoever and get point b
 
Level 22
Joined
Feb 6, 2014
Messages
2,466
To use movement speed of the missile while moving circular path, use s=rA (A: angle in rad) so you will have A = s/r. s = movement speed*0.03 and r = radius. You will then get the new polar offset. If the current Phase Angle is 45° and the calculated A is 15° (after converting to degree) then your new polar position for the missile is r<60° (or re^(2π*60i) if you don't like that notation). Though this will only work for stationary center. Fir moving center, it will cause the missile to have linear motion.

For the missile being left behind, this will cause the missile to not move in a circular path and end up moving in a linear path when left behind. To do that, you need to store the last phase of the missile (i.e. 30°). Lets say the calculated A = 5°, then your destination loc is r<35°. Get angle (lets call it A2) from current loc to destination loc and project the missile using that angle (x = currentX + speed*Cos(A2 in rad))
and do the same for y. If the missile's new loc is the same as the destination loc, store the new phase (which is 35°), else do the same again where phase is still 30°. Note that sometimes the new position will not exactly match the destination loc so you can just check distance of new loc to destination loc is let's say less than speed*0.03, then store the new phase
 
Last edited:
Status
Not open for further replies.
Top