YesNoOk
avatar

Make a character attack while lying down if enemy is near (Read 18495 times)

Started by CamChao, August 19, 2017, 06:21:02 am
Share this topic:
Make a character attack while lying down if enemy is near
#1  August 19, 2017, 06:21:02 am
  • *
    • USA
I'm currently making my first MUGEN character (Gideon Graves) and I want to make him attack an enemy while lying down if the enemy is near him (at least with low-enough health and/or with a random chance), since that's what the baddies do in the Scott Pilgrim game, but I don't know how to make it happen.

But I think I may be on the right track by giving his lying down animation a red hitbox to use it as a way to detect whether an enemy is close enough to Gideon to trigger his "lying down attack" animation.

And after the attack animation, rather than immediately get back up, I'd like him to go back into his lying down animation and then get back up as usual. Or, it might be a good idea to add a new state for him to go into after the lying down attack, with a new lying down animation that doesn't have a red hitbox, that way he doesn't do the lying down attack twice in a row. Or something like that. I don't know, I'm new to MUGEN character creating, so yeah.
Re: Make a character attack while lying down if enemy is near
#2  August 19, 2017, 03:10:58 pm
  • *****
  • Shame on you!
    • USA
red and blue clsn boxes are just the attacking box and the hitable box.
Like if there's no Red box, the hitdef wont work. If there's a red box and no hitdef, the red box wont work.
The blue box defines where your character can get hit.

P2Dist X and P2BodyDist X will tell you how close Player 2 is.
Go into Mugen class and look them up. Use DisplayToClipboard to watch their values. Once you see their values in debug, CTRL+D, you'll know what value to use in your code.

What you'll want is a new statedef that will be an attack. You'll need to define WHEN the button press happens WHY to go into it in the CMD file.
So because the move will be a "basic", probably just 1 button pressed, you'll have to make your own ChangeState.

Since you're new to this, Read this >> http://mugenguild.com/forum/topics/mugen-101-things-you-need-know-169758.0.html


Your idea can be done in one big state, or you can break it down into two states.  I'd say use the two states for now. Because your CMD is only going to let you do the move while your laying down the first time, you wont need 3 states.

Also, you may want to copy and paste Crouching Light Kick, and renumber it so it has a unique StateDef. This is how the CMD is going to find what state to use. The lay down kick will act a lot like CLK so copying it will make things easier.
At the end of the new laydown CLK state, use the changestate to switch to a new state.
That'll be your lay down state.

When you're finding out the values of the P2Dist X, look at what state you're in while laying down. You should be able to copy/paste and rename that. Just like you did with CLK (Probably State No 430)

Dont expect it to work flawless the first time. Just keep updating us and we'll help you along.
vVv Ryuko718 Updated 10/31/22 vVv
Re: Make a character attack while lying down if enemy is near
#3  August 20, 2017, 02:26:15 am
  • *
    • USA
Oh, it's not actually a kick. He swings his pixel sword while lying down. And I'd actually like the attack to happen automatically when P2 is near him, not when a button is pressed. Sorry, I should've been more clear.
Here's a video of him doing it in the game quite a few times so you can see exactly what I want him to do in MUGEN. Notice he never does it more than once each time he lies down. That's why I mentioned making a new lying down state for him to enter after he swings his sword while lying down, so he doesn't do it again until next time he lies down. Unless making the new lying down state wouldn't be necessary?

Skip to 7:39 for the Gideon fight.
Re: Make a character attack while lying down if enemy is near
#4  August 20, 2017, 03:32:06 am
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Pardon my response if a bit clunky, on mobile :)

In the liedown state just do a changeanim with persistent = 0.  Let's say it's anim 1234.
Changeanim
Trigger1 = p2dist x < 50
trigger1 = Random < 50
value = 1234
Persistent = 0

Use that anim # in the HitDef's triggers.
HitDef
triggerall = anim = 1234

Be sure to change MoveType to A (attack) while attacking (same trigger as above)

Do another Changeanim back to the liedown anim when attack is finished
Changeanim
trigger1 = anim = 1234 && animtime = 0

Be sure to set MoveType back to L or H I forget offhand.  Again, same trigger as above

Re: Make a character attack while lying down if enemy is near
#5  August 20, 2017, 04:45:36 am
  • *
    • USA
Ooookay, I don't think I follow.
I'm making Gideon use his own common1.cns file rather than the one in MUGEN's data folder (I copied and pasted it into Gideon's folder), which I think might be the correct thing to do. But I'm confused on what to do.

In the common1.cns file, underneath all of the [State5110, 16] stuff, I put
Code:
[State 5110, 17]
type = ChangeAnim
trigger1 = p2dist x < 50
trigger1 = Random < 50
value = 260
Persistent = 0
(260 is the lying down slash animation)
Now, Gideon plays the lying down slash animation when P2 comes near him, but he has a chance of doing it repeatedly until it's time for him to stand back up (I know it's because I haven't implemented any code to stop him from doing it more than once yet). Was this the correct thing to do? I know I'm not finished with this yet, but I still feel that I should ask. I assume that "Random < 50" gives him a 50% chance to play the animation? Or at least I think it's supposed to. Without the code to keep him from playing the animation more than once, it seems that he has a 50% chance to play the animation every tick or something like that. :P

I don't understand where I should put the HitDef, the triggerall and the anim #, the MoveType = A, the ChangeAnim with trigger1 = anim = 260 && animtime = 0, and the MoveType = L or H (whichever it is). Not sure what you mean by "same trigger as above," either. Sorry if I'm being difficult. :(
Re: Make a character attack while lying down if enemy is near
#6  August 20, 2017, 10:12:02 am
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Ooookay, I don't think I follow.
I'm making Gideon use his own common1.cns file rather than the one in MUGEN's data folder (I copied and pasted it into Gideon's folder), which I think might be the correct thing to do. But I'm confused on what to do.

In the common1.cns file, underneath all of the [State5110, 16] stuff, I put
Code:
[State 5110, 17]
type = ChangeAnim
trigger1 = p2dist x < 50
trigger1 = Random < 50
value = 260
Persistent = 0
(260 is the lying down slash animation)
Now, Gideon plays the lying down slash animation when P2 comes near him, but he has a chance of doing it repeatedly until it's time for him to stand back up (I know it's because I haven't implemented any code to stop him from doing it more than once yet). Was this the correct thing to do? I know I'm not finished with this yet, but I still feel that I should ask. I assume that "Random < 50" gives him a 50% chance to play the animation? Or at least I think it's supposed to. Without the code to keep him from playing the animation more than once, it seems that he has a 50% chance to play the animation every tick or something like that. :P

I don't understand where I should put the HitDef, the triggerall and the anim #, the MoveType = A, the ChangeAnim with trigger1 = anim = 260 && animtime = 0, and the MoveType = L or H (whichever it is). Not sure what you mean by "same trigger as above," either. Sorry if I'm being difficult. :(

The states found in common1.cns (MUGEN data folder) are default states which will be used unless they are found in your character's own .cns
If you add one of those state numbers to your character's own .cns, the one in common1.cns will be ignored.

So if you create State 5110, the default one will be ignored.

Best thing to do is copy the entire state from common1.cns and work from there

Spoiler: Default State 5110 (click to see content)

This is one of those states that MUGEN handles differently, hardcoded.  So I was suggesting you add this...

Spoiler, click to toggle visibilty

...but I tested it, and the changeanim is likely bugging it.

So you should instead just add a ChangeState to 5110, sending to an attack state.  Also adding some more triggers for safety...

Code:
[State 5110, Randomly change to attack state]
type = ChangeState
triggerall = alive
triggerall = anim = 5110 ;currently in liedown anim
triggerall = vel y = 0 && vel x = 0
trigger1 = p2dist x < 50 ;p2 nearby
trigger1 = random < 10 ;basically 1% chance per tick
value = 260
persistent = 0

PS: "random" as a trigger generates a random number from 0-999 every tick.  random%50 will generate a number between 0-49 every tick

Last Edit: August 20, 2017, 10:15:30 am by altoiddealer
Re: Make a character attack while lying down if enemy is near
#7  August 20, 2017, 07:26:31 pm
  • *
    • USA
I added the [State 5110, Randomly change to attack state] code, but this resulted in giving Gideon a random chance to stay permanently lying down if P2 comes near him, with a warning in the debug saying, "Player Gideon Gordon Graves (57) in state 260: Changed to invalid state 260 (From state 5110)"

So I added this:
Spoiler, click to toggle visibilty

And, well... it works now, but he still has a chance to play the animation multiple times. Also, after he plays the animation, he acts like he's landing on the ground again. And the HitDef doesn't work.

I show the hitboxes in the video to show that the red clsn boxes are actually touching the other Gideon's blue clsn boxes. (I know, the red clsn boxes aren't pretty, but that's not what we're talking about right now)
Re: Make a character attack while lying down if enemy is near
#8  August 21, 2017, 12:13:44 am
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
I'm not sure if Time = 0 is the issue with the HitDef not taking effect - try adjusting that.

Also, maybe try to ChangeState to the default get up from knockdown state instead of back to 5110.  Unsure what that stateno is offhand

Re: Make a character attack while lying down if enemy is near
#9  August 21, 2017, 12:25:44 am
  • ***
  • What's a title
  • Novice M.U.G.E.N. creator
    • USA
    • sites.google.com/site/rmaster007smugensite/
Try using AnimElem instead.
Spriting is harder than I thought.
Re: Make a character attack while lying down if enemy is near
#10  August 21, 2017, 02:55:46 am
  • *
    • USA
I've now changed the ChangeState to the get up from knockdown state, but since I didn't want it to happen immediately after the lying down slash animation, I added his default lying down sprite to the end of the lying down slash animation and made it last for 10 ticks as a workaround. It works much better, and he now slashes only once (or a random chance of not slashing at all, which is also what I've been wanting).

I tried adjusting the Time = 0 in the HitDef, but it still didn't work. I switched it to AnimElem = 1 and that's not working either. I think this is now the only problem I'm having with this whole thing.

Video here
Spoiler, click to toggle visibilty
Re: Make a character attack while lying down if enemy is near
#11  August 21, 2017, 07:05:05 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
From your previous video, it looks like the red hitbox is only on animelem 2, not on animelem 1.

A little tip for bug testing: I usually start off by making very drastic changes to try and pinpoint the problem, before making the code correct.  So I probably would have changed the trigger to like

trigger1 = 1

If it still misses, then you know the problem lies elsewhere.

Re: Make a character attack while lying down if enemy is near
#12  August 22, 2017, 01:16:31 am
  • *
    • USA
Well, it seems that the reason the attack wasn't hitting is because I had the movetype in the HitDef set to L for Liedown. I changed it to S for Stand and it now works! Thanks for all your help, people! :)