The Mugen Fighters Guild

Help => M.U.G.E.N Development Help => Code Library => Topic started by: Bea on February 05, 2004, 11:53:55 am

Title: Aimed projectile
Post by: Bea on February 05, 2004, 11:53:55 am
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 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.
Title: Re: Aimed projectile
Post by: Messatsu on December 12, 2007, 06:47:12 am
I have made use of your math skills yet again, Bia.  Thanks! :sugoi:
Title: Re: Aimed projectile
Post by: Cybaster on December 12, 2007, 11:49:59 am
I didn't even remember that Mugen had Exp and Ln. o_O
A simple ** operator would have been easier. ^_^

Quote
Well, now I have to find the next funny formula to code in mugen... :P
Since you've already done Bezier curves, may I suggest Hermite curves (http://en.wikipedia.org/wiki/Hermite_curve) ? :P
Title: Re: Aimed projectile
Post by: Bea on December 12, 2007, 04:35:26 pm
Messatsu: You're welcome. It's good to know that someone is using an almost three years old code. ^_^

Cybaster: Sounds like a challenge. I'll take a look on it as soon as I get motivated to work with mugen again. :)
Title: Re: Aimed projectile
Post by: ultimatedude on December 12, 2007, 07:14:50 pm
Awesome, thanks, I was trying to make an aimed projectile for a while, thanks

I would have never found it out, all those wierd stuff you used :S
Title: Re: Aimed projectile
Post by: Alchemist on December 18, 2007, 04:44:56 pm
Thanks for you efforts I think i'll be needing this, question though, what if the projectile has a point and you wanted the anim to face the correct angle, how would 1 go about coding that? (not a math guy in the slightest way  :S)

edit: *nevermind I think you've covered it in a previous topic, you rock  :sugoi:*
Title: Re: Aimed projectile
Post by: SesakaX on November 29, 2008, 08:07:52 am
Wow....Amazing!
I can try that code out for my character that I'm working on. Thanks for sharing! ;)
Title: Re: Aimed projectile
Post by: Tyrannosaurus rex on June 08, 2009, 06:42:18 pm
How exactly is the code used. Is it suppose to function like a sprite pointing in various directions with a gun to shoot in any given angle?