The Mugen Fighters Guild

Help => M.U.G.E.N Development Help => Code Library => Topic started by: Maj' on January 23, 2005, 09:58:18 pm

Title: Auto-aim projectile stuff.
Post by: Maj' on January 23, 2005, 09:58:18 pm
When I was browsing through some of my old shit, I found this piece of code...

------------[piece of code]----------
projectile (helper)....

[State 0, ]
type = AngleSet
trigger1 = time = 0
value = (atan((p2bodydist y-86)/(ifelse(facing = 1, enemy, pos X - Pos X , Pos X - enemy, Pos X)))*(-180/Pi))

[State 0, ]
type = AngleDraw
trigger1 = 1

[State 8000, VelSet]
type = VelSet
trigger1 = time = 1
x = (90-(atan((p2bodydist y)/(ifelse(facing = 1, enemy, pos X - Pos X , Pos X - enemy, Pos X)))*(180/Pi)))/10
y = -(atan((p2bodydist y-86)/(ifelse(facing = 1, enemy, pos X - Pos X , Pos X - enemy, Pos X)))*(-180/Pi))/10
....
------------[/piece of code]----------

I thought it was interesting. I haven't seen much characters needing auto aiming projectiles though.
It's not really about the code, but about the formula. If you need more help or explenation on this, feel free to ask.

Title: Re: Auto-aim projectile stuff.
Post by: Bronko on January 24, 2005, 12:57:41 am
If someone made an SSBM style samus...
Title: Re: Auto-aim projectile stuff.
Post by: Bahn on April 13, 2005, 03:21:06 am
Useful for replicating Shadow Lady's Galaxy Missile perhaps? How would I make it multiple projectiles?
Title: Re: Auto-aim projectile stuff.
Post by: BlackJack on April 13, 2005, 03:23:53 am
Shadow Lady, Sektor (or was it Cyrax?), etc...

How would I make it multiple projectiles?
Add this code to any projectile the character creates.
Title: Re: Auto-aim projectile stuff.
Post by: Winane on April 13, 2005, 03:25:24 am
How would I make it multiple projectiles?
By making multiple helpers and putting them all into the state with that code, perhaps?  ???
Title: Re: Auto-aim projectile stuff.
Post by: BlackJack on April 13, 2005, 03:39:33 am
^-- yes, the opposite of what I said, and it's better. :P

Another method would be:

SMEE IIRC said:
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
Title: Re: Auto-aim projectile stuff.
Post by: Winane on April 13, 2005, 05:39:08 am
Yeah, SMEE posted that in this thread (http://www.mugenguild.com/forumx/index.php?topic=8060.0).  That'll work if you'd rather use a Projectile than a Helper, and if you don't mind the projectile's animation not being rotated.  Though that can be worked around, by including a range of angled animations in the AIR file, and choosing which anim to use based on the calculated angle.
Title: Re: Auto-aim projectile stuff.
Post by: Bronko on April 13, 2005, 05:37:37 pm

Edit:
Once the projectile is aimed, you shouldn't need to make seperate calculations to find the angle of rotation, just use it's velocity.
http://www.mugenguild.com/forumx/index.php?topic=21303.0
Title: Re: Auto-aim projectile stuff.
Post by: Cyanide on July 25, 2005, 06:58:12 am
Gotta add something to this. I recently tried to use this code to make a missile face p2 after spinning in place for a few seconds and found it to be badly inaccurate (missile facing down original sprite) came out in all sorts of wacky angles. Anyway i changed the sum around a lot for the angledraw and this has given me good results over 5 tests

fvar(3) and var(2) have been set to p2dist Y and enemy, pos X respectively

Code:
[state blah]
type = angleset
trigger1 = 1
value = 90+(atan((fvar(3))/(ifelse(facing = 1, var(2) - Pos X , pos X - Var(2))))*(-180/Pi))

Also found that it must be facing P2 if it wasn't it inverted the direction ie missiles back facing me.

I think i'm gonna have to work on the velset bit too as that rocketed them off sideways at the speed of light.