Don't forget to read the rules of the forum. No current release restrictions. |
Help Search Members Calendar |
Logged in as: The Dreamslayer ( Log Out ) | My Controls · 0 New Messages · View New Posts · My Assistant |
SMI |
Posted: Feb 5 2004, 10:54 AM
|
Member Group: Members Posts: 62 Member No.: 111 Joined: 14-September 02 |
Hello, hello, hello.
After having messed with angles in mugen, I couldn't help but waste my whole night thinking in normals, vectors and so on... I almost lost my sleep due to that... :P So, the first thing I did today as I got myself to my computer was to program a code for aimed projectiles based on the calculus of a normalized vectors. So, here is the code :P: ;Finds the X component of the vector Player, EnemyNear ;Formula to find the components of a given vector AB ;V(x) = B(x) - A(x) ;V(y) = B(y) - A(y) [State 1640, X] Type = VarSet Trigger1 = 1 fvar(13) = (EnemyNear(0), Pos X - Pos X) * Facing ;Adjust the direction towards player facing ;Finds the Y component of the vector Player, EnemyNear [State 1640, Y] Type = VarSet trigger1 = 1 fvar(14) = (EnemyNear(0), pos Y - Pos Y) ;Finds the vector length ;Formula of the length of a given vector AB ;|AB| = (AB(x)^2 + AB(y)^2)^1/2 [State 1640, Vector Length] Type = VarSet trigger1 = 1 fvar(15) = Exp(0.5*ln((fvar(13) * fvar(13))+(fvar(14) * fvar(14)))) ;To find the normalized vector one has to use ;the following formula: ;Normal(AB) = V(AB)/|AB| ;So, you divide the X and Y components of one vector by it's length ;Obs: ;Normalized vector = The normalized vector of X is a vector in the same direction ;but with norm (length) 1. ;Now that we have the normalized vector, we multiply it by the desired absolute velocity, ;such as 5 pixels per frame. ;Projectile [State 1640, Projectile] Type = Projectile trigger1 = animelem = 2 projanim = 1010 projhitanim = 1020 projremanim = 1020 projremovetime = 240 projpriority = 1 projshadow = -1 projsprpriority = 2 projid = 1000 offset = 0 ,-35 velocity = (Fvar(13)/fvar(15)) * 5.0, (FVar(14)/fvar(15)) * 5.0 ;Normalizes the components ;and multiply by the desired absolute velocity. attr = S, NP hitflag = MAF damage = Floor(((3 + (3 * Random/1000.0)) * Fvar(28) + 0.5)), Floor(1 + (Random/1000.0) * Fvar(28) + 0.5) animtype = Hard guardflag = M pausetime = 0,12 sparkno = 1 sparkxy = 26,0 hitsound = 5, 2 guardsound = 6, 1 guard.sparkno = 40 ground.type = High ground.velocity = -2.4 ground.slidetime = 12 ground.hittime = 12 air.velocity = -2.4,-4.5 air.fall = 1 air.recover = 0 ignorehitpause = 1 getpower = 50, 75 givepower = 20, 30 Well, now I have to find the next funny formula to code in mugen... :P kisses. -------------------- [murray voice]
I'm a powerful demonic force! I'm the harbinger of your doom! And the forces of darkness will applaud me as I stride through the gates of hell carrying your head on a pike! [/murray voice] |