So i have been making a platformer and i want the player to be able to attack and move at the same time, and the only way i´ve managed to do that is trough making the player and the arms different objects, but i would rather not have to do that as it would make me have to split the animations in two and stuff like that, does anyone have a solution for my problem?
If you mean you want ability to attack while not moving + ability to attack while moving
Then i would question is splitting animations not the right choice
Cause most games i know have that kind of gimmick do go for separate animations
Not just for arms and torso but whole character frames
Top frames i put inside rectangle are used for standing attack
While ones on the bottom are for attacking while moving
And below you can see separate animation frames for attacking while jumping
I saw here a guy who was trying to do metroid clone
Where this characters arm could aim up or diagonally up i think diagonally down also
And he had A LOT of problems managing it
Cause when player jumps he needed to change it to different arm object
When player turned into the ball he needed to delete the arm
Which means he needed to create/delete arm object depending on what was happening in the game
Imagine that hell if player spamed some controls
I would really suggest you reconsider if making separate animations is really a bad idea
Cause either you sacrifice your time on separate animations for each scenario
Or you gonna sacrifice it on creating/deleting/managing your arms or whatever is your separate object + bug fixing
Where with animation it will just as simple as making sure correct animation is playing in correct moment
Oh, well, i meant to say that i wanted to make one animation play for running and attacking, and one animation for standing still and attacking, while it all being a single object, but perhaps you did in fact understand it that way, If that is the case then are you basically saying that i should probably split the arms and the body into 2 objects?
By the way, as you may have noticed i am not a native English speaker, so sorry if i interpreted it in a wrong way,
I am saying quite the opposite
I would go for having one object
And animations for each scenarios
Where only if you would have a gun for your object then it to be separate object
I would not separate arms or parts of my player unless my game would absolutely require it
For example if you would make arms that can rotate or work independently than rest of player
But that would be ultra rare scenario
You have most likely same problem as everyone
You cannot just allow something to happen like set animation to something and expect it to change only when you want to
You also need to prevent it from happening/playing when it should not
This is a lot of logic work but doable
Let me give you example
You set animation to walk when player is moving
You set animation to jump when player is jumping
You set animation to idle when player is not moving
You set animation to fire when player is firing
Everything for you seems OK here?
Let’s find out
Tell me which animation should play when you are firing while jumping?
Which animation should play when you are firing while not moving?
Which animation to play when you are jumping and moving?
Now you see the problem?
Restrict your animations from playing when you don’t want to play them
Otherwise 2 or more animations to play at the same time and animations will get stuck
For example
You set animation to walk when player is moving
Player is on the floor
Player is moving
INVERTED player is firing (or more likely player animation is not firing/fire key is not pressed)
You set animation to jump when player is jumping
INVERTED player is on the floor
INVERTED player is firing (or more likely player animation is not firing/fire key is not pressed)
INVERTD player is moving
And now you need to copy that event make Player is moving NOT inverted and change animation to MovingJump
You set animation to idle when player is not moving
Player is on the floor
INVERTED player is firing (or more likely player animation is not firing/fire key is not pressed)
You set animation to fire when player is firing
SOME key is pressed for example Z to fire
Player is on the floor
INVERTED Player is moving
And now you need to also copy that and add separate animation for if player is moving
And repeat it for jumping firing animation
But by now you should have general idea how to do it
Its not rocket science its something we all needed to sit upon and learn
Look, thanks for trying to help but as you can see in the images I posted on the comments I already did that, I’m having a problem with the animation starting to play
Wait you want to tell me i did not understand what you want to do?
I mean from what you wrote i get that you have problems with making animation of your player play when you run and fire at the same time
Where you want it to play animation of firing while running
Where i bet you have also animation for just running without firing when you just move
But now that i think of it i do not understand what kind of problem you have?
Animation gets stuck it don’t play at all or what?
If i was wrong then can you describe your issue in more detail?
I do not need screenshot i need you to explain what is happening you do not want
And what you would want to happen
Ok, so, what happens when i press the attack button while moving is the running animation simply starts again on frame 1, that’s it, the character doesn’t stop running or anything, the running without attacking animation just resets.
And you want when you press attack button while running
A - player stops and attack animation is played?
B - player keeps running and moving attack animation is played?
Cause what i did explain you so far is for B which also it fixes issue of it getting stuck on 1st frame
So… i’m so sorry, but turns out, the only reason why my code wasn’t working was because FOR SOME REASON, there were 3 lines of code on the bottom telling the player to play the walking animation, and since they didn’t have any other conditions except player is moving and player is on ground, they were overwriting all of the rest. Once again, i am so sorry for wasting your time and i hope you have a great whatever the heck it is there for you!