Attack animations set by mouse click and mouse direction

Hey,

So as the title says, I want to play attack animations based on a mouse click and the direction that the mouse is moving.
So the left mouse button gets clicked and the attack start animation gets played which is pretty much the character holding the sword back.
Then the left mouse button gets released and the attack end animation gets played which is the character swinging the weapon.
Then animation that gets played depends on which way the mouse gets moved.
Here’s a badly drawn diagram of what I’m trying to accomplish:

This is my blue print so far:

As you can see I have only one attack set on clicking and releasing so far because I’m not sure how to implement the movement of the mouse.
So if the the mouse is clicked and moves right then I want the character to start the swing from right animation, then once the mouse click is released it plays the attack end animation.

Any thoughts?

Thanks

I’ve got the animations pretty much ready, just need to sort out the bone weightings properly.

So if the mouse gets clicked and moved right the character does this:
99d702d4110a2f58b70a1b4d96988d5101db4e53.jpeg

If the mouse gets clicked and moved left the character does this:
f87ff4a6e2b0b2dde4b2dd47f44087ef236d3a87.jpeg

If the mouse gets clicked and moved up the character does this:
999e9388c8f069e5e08c2b97f512315e65f077dc.jpeg

If the mouse gets clicked and moved down the character does this:
7d50c741e4cf6e9d1c7bff1d2d32ae744048c6e0.jpeg

How would I go about sorting out the direction of the mouse in a blueprint?

Thanks

You can maybe check the input axis values coming from your mouse when you press your mouse button? So that if X axis is positive it’s like moving the mouse to the right. You could even use the value of the input to determine how fast your mouse is moving at the point of clicking the button if you need that for some reason. And maybe picking whichever value is greatest when deciding whether to choose between whether it goes left or down when moving the mouse diagonally. And you could also use a really short delay after clicking the mouse to check for the movement direction if that’s something you’d want to do.

Hey, I’ve been thinking over this and had a go.
Not a very good go but I still had a go.
dc380235f0d2e7838ccb79bb23a037a8a3d41de5.jpeg

What I think I need to do is get the mouse location and see how far or which direction its moved from that point.
I’m really not to good with this sort of stuff. I’ve come along way since I’ve started but when it comes to vectors and locations I get quite lost as to what I need to do.

Could some one give me hand?

What I need to do is a branch with the condition set to if the mouse moves this direction then play this animation.
I’m just having trouble figuring out how to get the mouse direction and setting it as a condition.

Getting the mouse rotation input is quite straight-forward; have a look:

  1. Create a Mouse X Axis Input (Mouse X will give you the horizontal mouse direction). Choose “1” in Scale as shown in the following screenshot:

58a6d92fba499c5525b68f52543e5a5792a92d7e.jpeg

  1. Create a BP (you can use your character BP for that) with your Input. The float value will provide you with a float variable that contains how much the user moved the mouse horizontally, in which:
    Float > 0 = Right
    Float < 0 = Left

4200d9fb2f70078b9a5022f0890f0d8831bbd364.jpeg

So in your case you could set up, in your Animation BP, a transition like the following:

If Float > 0 => Play right animation
If Float < 0 => Play left animation

You can see how to set up the Animation BP and connect it to the Character BP in Zak Parrish UE4 tutorials.

Let me know if the above works!

Hey thank for the response! :slight_smile:

From the info you gave me I’ve managed to string something together. Although it doesn’t work 100% how I would like it to.
What I want to happen is if the player clicks and then moves the mouse in a direction then the animation gets played.
What actually happens with what I’ve done is what ever the position of the mouse is when the player clicks is the animation that gets played. So it takes the position from where the mouse was when clicked rather than the direction the mouse is moving after the mouse was clicked.

Images of what I’ve done so far:


This is pretty much self explanatory.


This gets where the mouse is and plays the correct start animation and sets a bool to true.


This plays the correct end animation that’s set by the bool when the mouse button is released.


And this runs the trace that deals damage.

Also with what I’ve done so far is that the mouse position has to be pretty precise other wise either the animation wont play or the wrong animation plays.
Instead what I’m looking to do is have an area range that the mouse can move in to get the desired attack animation to play:

Any tips and input greatly appreciated!

Thanks!

I would just use something like this for detecting which way the mouse is being moved. The short delay means that you can click and then drag instead of having to already have the mouse in motion while clicking.

You can get the axis values with a node so you don’t have to set variables for them yourself. Then compare their absolute values (because they can be minus and plus values) to detect which way the mouse is moved more than the other. (You could also add a value to one of them to turn the X shape of directions wider or narrower in either direction.) Then just compare the values for whichever axis was picked to determine if it’s positive or negative or 0, if you want some kind of default action to happen when you’re not moving the mouse.

And of course you can have the mouse click release avoid checking for any mouse movement and just get the animation montage that’s playing and based on that play the right end attack animation.

Hope this helps.