Download

How to make the character attack in the camera dirrection while strafing

Hi. I am working on a game third person action game with “over the shoulder” camera type. I have enabled “rotation yaw” in order for the character to always face the direction the player is looking. I have implemented a blendspace, so the character will animate properly when strafing, with its head facing forward.

strafing1.jpg

In the Anim Graph, I have added two “layered blend per bone” nodes, for two slots: one to play the animation for entire body when the character is not moving, and the other to play the animation only for the upper body when it’s moving.

Now, the problem is that everytime I play an upper body animation montage for attack, the character plays that animation, but not in the front, it plays in the direction it is moving. Is there a way to automatically rotate the root bone for the upper body slot animations, so the character always attacks in the direction the player is looking ?

978a8ba61ab195e422c8ae4d0211c48f068c0714.jpeg

Use the state machine for whole body animations (including your not moving ‘idles’) and blend by bone when you want to blend different parts differently. I.e. top with bottom because attack. You can put a blend space into the state machine states.

Thanks for your answer. It seems that I wasn’t very precise when explaining. The 2D blend space was already inside a state machine, but used only for movement. In the case of attacks, each attack animation has a corresponding animation montage. For these animations, I am using two slots:

Default Slot - All attack montages that have Default Slot selected make the character move only its upper body
StoponGround- All attack montages that have this slot selected make the character play the attack animation with the whole body, including legs.
anim.jpg

Here is an example of what I want to achieve:

Notice that when the player presses the S key and character is strafing, when it attacks, it doesn’t turn 90 degrees to the left, it attacks forward. In my case, the attack animation that goes through the Default Slot (for upper body) turns depending on W or D strafing. I could fix this by, as you could see in the script in my last post, detecting movement and countering that animation rotation. However, this is not a good method, since just for keyboard, for a single attack, I would need at least 4 copies of the animation, rotated in different ways (for A pressing- attack turned right 90 degrees, for D pressing- attack turned left -90 degrees, for A+W press- attack turned right 45 degrees, for D+W press- attack turned left -45 degrees). If I add a game controller, this gets even more complicated.

Now, how could I make the character allways play attack animation forward, no matter what is its strafing dirrection?

I have even tried to somehow rotate the root by using Transform (Modify) bone, but I get an error that no components to modify selected, altough I set the rotation for the root to 90. Mabie somehow I could feed in player character control rotation, so the attack animation will allways play forward.
d21a30d54def35cbd18dba09897b2ac889886a11.jpeg

I’ve done some research and it seems that some people encountered the same problem (minute 13 from the next video)

Hopefully this would make it more clear what doesn’t work well:

https://youtube.com/watch?v=BN0geW9QNcs

P.S. Sorry for another post but on a small phone’s screen it is very hard to make proper edits, especially when pasting stuff.

I’am interested in the solution! have you find any proper way of doing this? thanks.