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

[JASS] Need math code for Mirroring Angles!

Status
Not open for further replies.
Level 18
Joined
Oct 18, 2007
Messages
930
Ok for my new so called "spell" i need some kind of math code to mirror an angle to make it look like it bounces of the things it hits.

Ok an example picture is needed i think ;)
attachment.php


Hope you all understand and please comment if you do. Thx
 

Attachments

  • Untitled-1.png
    Untitled-1.png
    344.2 KB · Views: 848
Level 14
Joined
Nov 18, 2007
Messages
816
JASS:
// pure pseudocode
local real ang = Atan2(GetUnitY(obj)-GetUnitY(inc), GetUnitX(obj)-GetUnitX(inc)) // obj is a static object, unable to move; inc is the incoming unit
local real sang = Atan2(inc.speed.y, inc.speed.x)
local real newang = bj_PI + (2*ang) - sang
    set inc.speed.x=Cos(newang)*inc.speed.amount
    set inc.speed.y=Sin(newang)*inc.speed.amount
two units colliding.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
if you have a x velocity and a y velocity you can do it like this:
JASS:
...
if IsPathable(x + xvel, y) then
    set xvel = xvel * -1
endif
if IsPathable(x, y + yvel) then
    set yvel = yvel * -1
endif
...
I hope you understand what I mean.
 
Status
Not open for further replies.
Top