Jump to content
  • 0

Weird left/right attack rubberbanding (custom anims)


gooby

Question

I've been trying to randomize between punch/kick animations for unarmed attacks. For some reason facing left/right has this weird rubberbanding while facing up/down is totally fine and works as intended. It's not my sprite sheets because with just a single anim it looks fine.

Could someone help me figure out whats wrong?

 

You can see it here: 

https://www.ascensiongamedev.com/resources/filehost/221ce97388872e86ca7e6126bbfa0fd2.mp4

 

code in Intersect.Client.Entities.Entity.cs/UpdateSpriteAnimation: 

Spoiler

public int punchOrKick = 0;  

...

else if (AttackTimer > Globals.System.GetTimeMs()) //Attacking
            {
                var timeIn = CalculateAttackTime() - (AttackTimer - Globals.System.GetTimeMs());
                LastActionTime = Globals.System.GetTimeMs();

                if (punchOrKick == 0)
                {
                    if (AnimatedTextures[SpriteAnimations.Punch] != null)
                    {
                        SpriteAnimation = SpriteAnimations.Punch;
                        SpriteFrame = (int)Math.Floor(timeIn / (CalculateAttackTime() / 3f));
                    }
                }
                else
                {
                    if (AnimatedTextures[SpriteAnimations.Kick] != null)
                    {
                        SpriteAnimation = SpriteAnimations.Kick;
                        SpriteFrame = (int)Math.Floor(timeIn / (CalculateAttackTime() / 3f));
                    }
                }

                if (SpriteFrame == 0)
                {
                    //randomize between punch and kick anims
                    Random random = new Random();
                    punchOrKick = random.Next(2);
                }

 

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0
1 hour ago, gooby said:

could it be something to do with that when trying to walk and attack simultaneously another weird thing happens, like it's trying to reset a base walk frame between each attack frame? this is something that started happening to me after the last anims update.

You should only set one sprite animation for each action and one action should be dominant on other. For example attack frame could have more priority so when the player move and attack, only attack frame is displayed. Right now it looks like animation sprite switch between both. You should check your if condition to see if everything is fine.

 

Knowing this could be helpful too:

There is a small lap of time where the character stop walking and when he does stop walking, the default sprite animation is set (it could be the kick one on this case). The idle timer variable can help on this I think.

Link to comment
Share on other sites

  • 0

Does both punching and kicking on their own really look fine? That genuinely looks like a sprite issue if you don't change the destination rect. 

 

Now for random code nitpicks:

There's no need to make a new Random instance. There's a Randomizer class in the source that has an instance for it already. 

 

And is there a reason why punching and kicking is public if it's only used within the Entity? 

Link to comment
Share on other sites

  • 0
1 hour ago, Joyce said:

Does both punching and kicking on their own really look fine? That genuinely looks like a sprite issue if you don't change the destination rect. 

 

Now for random code nitpicks:

There's no need to make a new Random instance. There's a Randomizer class in the source that has an instance for it already. 

 

And is there a reason why punching and kicking is public if it's only used within the Entity? 

yes they both look just fine on their own. could it be something to do with that when trying to walk and attack simultaneously another weird thing happens, like it's trying to reset a base walk frame between each attack frame? this is something that started happening to me after the last anims update.

 

and thanks for nitpicking, i did not know about the existing randomizer and shouldve made punchOrKick private. as a noob, i try to make stuff functional before proper.

Link to comment
Share on other sites

  • 0
1 hour ago, Shenmue said:

You should only set one sprite animation for each action and one action should be dominant on other. For example attack frame could have more priority so when the player move and attack, only attack frame is displayed. Right now it looks like animation sprite switch between both. You should check your if condition to see if everything is fine.

 

Knowing this could be helpful too:

There is a small lap of time where the character stop walking and when he does stop walking, the default sprite animation is set (it could be the kick one on this case). The idle timer variable can help on this I think.

oo i see it now, i added something that made it slightly better.

but how can i differentiate between sprite frames when they all use the same variable SpriteFrame? do i make another int for each anim i want to use?
EDIT: i think id use SpriteAnimations.Punch, etc?

Edited by gooby
Link to comment
Share on other sites

  • 0
23 minutes ago, gooby said:

oo i see it now, i added something that made it slightly better.

but how can i differentiate between sprite frames when they all use the same variable SpriteFrame? do i make another int for each anim i want to use?
EDIT: i think id use SpriteAnimations.Punch, etc?

Actually, you can be fine with only one variable. You just have to be sure that the current SpriteAnimation is the one the sprite frame is acting on.

Link to comment
Share on other sites

  • 0

ok i figured it out, it was better for me to randomize animations in Client.Entities.Player.cs/Update() as such:

Spoiler

                if (AttackTimer < Globals.System.GetTimeMs())
                {
                    IsAttacking = false;
                    //randomize between punch and kick anims
                    punchOrKick = Intersect.Utilities.Randomization.Next(2);
                }

 

 

and i used IsAttacking similar to Shenmue's script to cancel the walk frame if attacking in Entity.cs/UpdateSpriteAnim:

Spoiler

            SpriteAnimation = AnimatedTextures[SpriteAnimations.Idle1] != null && LastActionTime + TimeBeforeIdling < Globals.System.GetTimeMs() ? SpriteAnimations.Idle1 : SpriteAnimations.Normal;
            
            if (IsMoving && !IsAttacking)
            {
                SpriteAnimation = SpriteAnimations.Normal;
                LastActionTime = Globals.System.GetTimeMs();
            }

 

 

it looks a little awkward to move+attack, so ill probably work on holding the player in place when attacking. thanks guys!

 

Video

Link to comment
Share on other sites

×
×
  • Create New...