• 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.

[Solved] Moving a Missile/something in a struct basic math question

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Hey there.

I'm working on a spell at the moment and I'm nearly there (I think I'm doing everything leakless in a nice struct and all clean and effective). It's just that my math isn't correct so the movement of the missile is looking very weird, but everything but the movement is acting correct.

Could anyone tell me what I should do in this scenario:

I made a spell that can target a position or a unit. (Something like Shockwave or Carrion Swarm per example)
I'm not using a 'missile' but instead I'm just changing x and y values so I can keep track of my 'invisible missile'. I do this with a timer of 0.05 as its interval.
This 'invisible missile' will create a special effect and do some damage at 0.3, 0.6, 0.9 and 1.2 seconds traveled.

The thing that's going wrong is the direction of the missile. My math is failing and I don't know how to set the new X and new Y of the missile every 0.05 seconds. This 'missile' is supposed to move 30 in the direction of the target of the spell, OR if no target was selected in the direction of the spell's targeted location.


EDIT:

I'm asking for help too fast! I just found out that I made a stupid typo!
Sorry!

This is what I had:

JASS:
set Dat.x = Dat.x + 30*Cos(Dat.angle)
set Dat.y = Dat.y + 30*Cos(Dat.angle)

It's supposed to be:

JASS:
set Dat.x = Dat.x + 30*Cos(Dat.angle)
 set Dat.y = Dat.y + 30*Sin(Dat.angle)
 
Also remember to multyply the angle by bj_DEGTORAD when you pass them to the sine and cosine functions, unless you are measuring your angles in radians already..

EDIT: another thing you might consider - if you substract the position vector of the target from the position vector of the missile, you get the angle between them. If you normalize that vector (divide it by it's length, so that the length becomes 1), and then multiply it by the velocity, you get the vector for the velocity! Amazing!
 
Last edited:
Status
Not open for further replies.
Top