The Mugen Fighters Guild

Help => M.U.G.E.N Development Help => Topic started by: Sean Altly on April 25, 2019, 02:59:56 am

Title: Throwing my helper like a projectile
Post by: Sean Altly on April 25, 2019, 02:59:56 am
Hey, so I've been pulling my hair out a bit trying to figure this out. The current character I'm working on has the ability to clone himself. He has a move called Stunt Double, which functions similarly to Sub-Zero's Ice Clone. However, I'm trying to add the ability for After Image to grab the clone and toss him at his opponent whenever he is within a certain distance (as in, close enough to grab the clone).

What I did was first create a move that when executed just looks like him throwing a copy of himself at you. I added the following triggers to the .cmd

triggerall = numhelper (1405) > 0
triggerall = command = "qcbk2"
triggerall = (statetype != A)
triggerall = var(19) = 1
trigger1=ctrl

This should ensure that he can only perform the move when the helper is present and when var(19) = 1.

Then within the helper's state where it's standing waiting to stun the opponent if attacked, I added this:

[State 0, ParentVarSet]
type = ParentVarSet
triggerall = time < 108 ;this is so that it can no longer be thrown once it starts to fade away
trigger1 = parentdist x = [-20,20]
v = 19
value = 1

This I thought would set var(19) to 1 whenever he is within 20 pixels of the helper, behind or in front (so like a 40 pixel window). I added varsets to reset it to 0 in various other states, such as the beginning of the state where the clone is thrown, and in state -2 to reset whenever the helper is not on screen.

I am a bit out of practice honestly and am not sure what's going wrong here. With the code the way it is, the throw never happens. If I change it to say parentdist x = [-50,50], suddenly it activates no matter where I am on the screen.

Any ideas here? Probably a really easy fix or simple mistake I'm making but I can't figure it out.

EDIT: Nevermind, I figured it out. I widened the window and then added varsets to set it to 0 when I was out of that range, I thought the way I coded it would make it set to 1 only in the window but it didn't. Whoops.
Title: Re: Throwing my helper like a projectile
Post by: altoiddealer on April 25, 2019, 06:45:54 pm
You probably don't need a var for this to begin with.  The parent can just use similar math, like:

triggerall = numhelper(1405)
trigger1 = abs(helper(1405),pos X - Pos X < 20)

Note: wrapping code in abs(**) will make the value always return a positive number.  -10 would be returned as 10.  It's very useful for certain things!


The reason the distance needed to be set greater than you expected, is because the distance is calculated by comparing the AXIS of player and helper - not the "edge distances."  You can have the code take the edge distances into account, it might just be a little more complicating though especially if the front/back edge distances are significantly greater, and if you want to start factoring in which way the helper is facing... etc.  If you want to do that just ask and I can help with that
Title: Re: Throwing my helper like a projectile
Post by: junkerde on April 25, 2019, 09:23:00 pm
Here's something similar I got stuck on a while ago that I figured out, similar in OP's case where you have to detect how far/close a helper is to you to execute something, in this case its detecting how far a static helper (X and Y coordinates) is from the parent and another helper projectile the parent shoots at it to activate it into a different state, example: (sorry for the sloppy coding, it might not be the best)

Helper(1003) = Static Helper
Helper(12100) = Helper Projectile (moves across screen on x axis)

Static helper state to change state when hit by helper projectile: (Notice how I use TURN, this is really important and makes it alot easier, and then having facing in the triggers)

Code:
[State 1011]
type = Turn
trigger1 = rootdist X < 0


[State 1011]
type = Changestate
triggerall = root,facing = -1 && Helper(1003),facing = 1 || root,facing = 1 && Helper(1003),facing = -1
triggerall = root,pos y  < Helper(1003),Pos y + 120
triggerall = root,pos y + 30 > Helper(1003),Pos y
triggerall = abs(Helper(1003),Rootdist y)-55 < abs(Helper(12100),Rootdist y)
triggerall = root,NumHelper(1003)
triggerall = root,NumHelper(12100)
trigger1 =  abs(Helper(1003),Rootdist X)-50 < abs(Helper(12100),Rootdist X) && abs(Helper(1003),Rootdist X)+ 40 > abs(Helper(12100),Rootdist X)
value = 1006

and then this is the helper projectile code to detect the distance between it and above, and when to dissapear into a remove state, to act as if it hit the helper:

Code:
[State 4902, 1]
type = changestate
triggerall = root,facing = 1 && Helper(1003),facing = -1 || root,facing = -1 && Helper(1003),facing = 1
triggerall = root,pos y  < Helper(1003),Pos y + 120
triggerall = root,pos y + 30 > Helper(1003),Pos y
triggerall = abs(Helper(1003),Rootdist y)-55 < abs(Helper(12100),Rootdist y)
triggerall = root,NumHelper(1003)
triggerall = root,NumHelper(12100)
trigger1 =  abs(Helper(1003),Rootdist X)-50< abs(Helper(12100),Rootdist X)
trigger2 = time > 100
value = 13001

Like the guy above me said, my problem initially was that the actual sprite is a circular shape so i had to account for how far out the projectile helper can hit and activate it, tricky part was getting both x and y axis but it worked. using Turn and facing is really one of the keys to get this right.