YesNoOk
avatar

Aimed projectile  (Read 7325 times)

Started by Bea, February 05, 2004, 11:53:55 am
Share this topic:

Bea

Aimed projectile
#1  February 05, 2004, 11:53:55 am
  • *****
  • MUGEN Grandma
    • Brazil
    • www.smeenet.org
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.
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 05, 2004, 12:02:30 pm by SMEE
Re: Aimed projectile
#2  December 12, 2007, 06:47:12 am
  • ******
  • In after lock
    • mugenguild.com/~messatsu/index.html
I have made use of your math skills yet again, Bia.  Thanks! :sugoi:


Many people risk their lives everyday by having Mugen.
Re: Aimed projectile
#3  December 12, 2007, 11:49:59 am
  • ******
  • Limited time to use Infinite power !
    • France
    • network.mugenguild.com/cybaster/
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 ? :P

Bea

Re: Aimed projectile
#4  December 12, 2007, 04:35:26 pm
  • *****
  • MUGEN Grandma
    • Brazil
    • www.smeenet.org
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. :)
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.
Re: Aimed projectile
#5  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

No Borders, No Nations
Re: Aimed projectile
#6  December 18, 2007, 04:44:56 pm
  • ***
  • Welcome to Die!
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:*
My youtube channel: http://www.youtube.com/user/AlchemistMI

Alchemist AKA Alcheymyst AKA H.F.C Alchey
Re: Aimed projectile
#7  November 29, 2008, 08:07:52 am
  • *
  • Literal Replicant Ego
    • www.sesakaheart.deviantart.com
Wow....Amazing!
I can try that code out for my character that I'm working on. Thanks for sharing! ;)

The cake is a PIe!
Re: Aimed projectile
#8  June 08, 2009, 06:42:18 pm
  • **
  • I'm a llama!
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?