# Angle between player and the nearest opponent  (Read 3079 times)

Started by Bea, February 04, 2004, 10:40:36 pm

#### Bea

##### Angle between player and the nearest opponent
New #1  February 04, 2004, 10:40:36 pm
• MUGEN Grandma
Okay, okay, okay. After a few minutes smacking my head against the wall, I gotta this code to calculate the angle between player and EnemyNear(0):
(Btw, I'm giving away a code to calculate absolute distance between player and EnemyNear(0) with it )

[State -3, Distance Between Player and the Nearest enemy]
Type = VarSet
trigger1 = 1
fvar(10) = Exp(0.5*ln((((EnemyNear(0), Pos X) - (Pos X)) * (( EnemyNear(0), Pos X) - (Pos X)) + ((EnemyNear(0), Pos Y - Pos Y) * (EnemyNear(0), Pos Y - Pos Y)))))

[State -3, M]
Type = VarSet
trigger1 = EnemyNear(0), Pos X != Pos X
fvar(11) = -((EnemyNear(0), Pos Y - Pos Y)/(EnemyNear(0), Pos X - Pos X))

[State -3, M] ;There can be no triangle if both points share the same X cord
Type = VarSet
trigger1 = EnemyNear(0), Pos X = Pos X
fvar(11) = 0

[State -3, Angle]
Type = VarSet
trigger1 = 1
fvar(12) = Atan(fvar(11)) * (180.0/Pi) ;Angle given in degrees.

And that was "Yet another code no one will use, nor will give a damn" brought to you by SMEE.
Now, there is no need to point out that no one other than would use this code.

Edit: Removed the ABS in the M formula and fixed the inverted cartesian plan that mugen uses by multipling M by -1.

Have fun.
Princess Adora: "My friend saw She-Ra take her dress off in the shower. She said she has an 8 pack. She said She-Ra is shredded."

SF2NES is dead. Long live SF2NES.
Last Edit: February 04, 2004, 10:51:10 pm by SMEE