Download

"Calculate Direction" node for blendspace direction

So I was having some trouble getting an angle that could be fed into a blendspace for a directional start animation. I found the “Calculate Direction” node and figured everything would be good. Well, it wasn’t at first. I searched answer hub and the forums, multiple people had the same problems I was having, but no solutions were to be found. I finally got it working, so I wanted to share my understanding. I don’t know if this will work with every actor/camera rotation and movement setup, but it works for my 3rd person shooter.

The first thing I realized was that the input velocity was always going to cause problems because it’s in world space. It has to be transformed into local space. In local space your forward and backwards movement will always be on the same axis no matter which way you’re facing, same with left and right. I got that working, but the rotation was still giving me issues. I guess this node was designed for a different setup than what my custom controller implements, because to get the output that I want, the input rotation should always be 0, 0, 0. The actor rotation is irrelevant, a 90 degree start is 90 degrees no matter which way you’re facing. This is a wild guess, but I think that this node gets the control rotation or something inside the function. That local space vector will only work when when you pass in 0 rotation, otherwise the engine think you’re making a different movement. There was one other problem, this one being as soon as the pawn starts moving you have to stop updating your output angle variable. Otherwise what happens is that the angle starts to decrease from for example 180 down to 90, this will cause it to switch from playing your 180 animation to your 90, which makes for a very ugly transition. I used anim notifies to set a bool that was used in a branch to determine if the angle variable needed to be updated. You also need to check in your transition rule if the character is moving before entering your start blendspace, because this node will give an idle output of 90.

Here’s my final setup:
Capture.PNG

(That multiplication node is there because I had my blendspace anims on the wrong sides.)

I hope what I wrote makes sense and that it helps anyone else out who has the problems that I had.

Hey MuchToLearn,

Thanks for posting this. Please continue to share anything like this in the future. Also, did you go ahead and post the solution (or a link to here) on some of those forum/answerhub posts with no resolutions?

Thanks,

Matt W.

Uhm, so I’m not sure if this is any help, but it is unclear to me what the issue is. However, i followed this guy’s tutorial on “direction” https://www.youtube.com/watch?v=2z9eWuT3sdA (I know i post this channel a lot). Well, it might be a similar fix, but I’m just guessing. Otherwise ignore :wink:

Good idea, those are the still the top two results when you do a Googel search for this node. I went ahead and added links to this thread.

I think it would be very helpful to expand the in-editor documentation for this node. The inputs that need to be used aren’t what a lot of us expected.

I think you might have linked the wrong video, that one is about controlling a camera. The issue that myself and others were having is getting the proper angle to determine which animation to play when the characters begins to move. This angle gets fed into a blendspace with animations for making start movements in directions other than in the character’s current forward vector.

Thanks for this MuchToLearn. I’m going to try this out as soon as I can. It was definitely frustrating having this problem for so long.

MuchToLearn,

Firstly, thanks so much for posting this.

Secondly, can you please post your Blendspace that you’re using this with? This is the exact same stopping point I reached working on my blendspaces and would love to finally…finally… be done with them!

Regards!

Sure, I actually have two blendspaces for start animations. One is used when there’s movement on the forward axis, the other is for strafe starts. The first one is what you’re interested in.

3bcf0f0fe6fa14638be8c3897b8825cb5d3ed39d.jpeg

It has variables of angle which ranges from -180 to 180 (the output of calculate direction), and speed which goes from 1 to -1. Forward and backward starts are set at 0 deg, speed is 1 and -1 respectively. Then the 90 degree and 180 degree anims are placed where they should be.

Only the start portions?

How come?

Sorry, I don’t understand. Do you want to see all of my blendscapes? The one that I posted is the only one that uses the calculate direction node. The others just use axis values from input events for direction on the X and Y axis, and the Last Movement Vector for stopping. This node just gives you an angle for start directions.

The start blendspace just makes a transition to another state that has my running blendspace.

@MuchToLearn It is still giving a output of 90 on default???

I think that’s normal, the 90 won’t be getting sent into the blendspace. It has been a long time since I looked at the output angles, but if I recall correctly it doesn’t matter what the idle angle is, as soon as you start moving it should give you the correct angle for directional change, and that is the one that gets fed into the blendspace so it should work if you have it setup as I do.

Muchtolearn you can show me how you get the axis i try but or i get -1, 0 or 1.

Thank so much

Direction

Hello. Our programmer “Glebasson” wrote the following calculation direction that is not dependent on the speed of your character and gives the right direction. Calculating comes from INPUT to the node “Add movement Input”.

Inputs:
All Axis mapping
W = 1.0
A = -1.0
S = -1.0
D = 1.0

737f85c675f79814ee6fa283fb02fb4052936646.png

Direction

Hello. Our programmer “Glebasson” wrote the following calculation direction that is not dependent on the speed of your character and gives the right direction. Calculating comes from INPUT to the node “Add movement Input”.

Inputs:
All Axis mapping
W = 1.0
A = -1.0
S = -1.0
D = 1.0

For whatever reason my character will not play the turning left animation. I set up turning animations outside of blendspace to make it simpler. What I have is a state for Turning Left and a state for Turning Right. I set up an Angle variable the same way you have here and I’m feeding that into the Transition Rule for Turning. Saying if Angle is > 0 Turn Right. That works. But saying if Angle is < 0 Turn Left doesn’t play anything. I’ve tested it out and Angle as you have it here only gives a positive value even though it’s described as going from -180 to 180. Is there something else you did in setting it up? What pin is Get Velocity and Get Actor Transform connected to?? I have it connected to Try Get Pawn Owner and that might be the problem but I’m not sure what to connect it to otherwise.

It will be helpful if you post screenshots of your graph, the transition rules, and then the logic inside the Turn Left state. What setup do you have for camera and control? My initial guess is that one of the inputs, either direction, transform, or the rotation is incorrect. You should add a print string node and evaluate the output of the Inverse Transform, make sure it’s correct.

It seems that when it’s standing still, Calculate Direction is always setting Angle to 90 and only changes + or - 180 when moving forward. But I need the turning to work when standing still :\ Actually, you and @Amaresh mentioned this. But for you, does it change once you start turning without moving forward/backward? Mine stays at 90.

I’ll post some screenshots.

c4cfccc149b2215804b57a68c8a987c5ed723e4b.jpeg

208f0f64e3ea45bbe06d4626914f408489d562e8.png

ece834b973a01ab2d43e2efbac767fe993fedc8a.png

9a7127f224c5bb0aa0e487c00777c629cdf62293.png

The last one is the exit Turn Right State Transition Rule which is basically saying if you’re not turning or if you start moving forward, stop Turning Right

I believe that forward input is necessary for this node to function correctly. Otherwise it can’t return an angle. When you move forward there’s a difference in the pawn and view rotations. As you move that delta is closed. However if you’re just pivoting the engine can’t tell what the final rotation should be. Think of a third person game, you can rotate the camera around the player, and then when you move forward the difference between the camera and pawn rotation are resolved. This gives you something that can be used for start direction. But in your case the pawn isn’t moving to the camera rotation.

I think what you need is to use your X axis input. Check if speed is 0 and if the character is receiving input to move right/left.

That’d work for a main character but I want to make a boss enemy that stays still and plays turning animations when turning to fight you so having it set to Input Axis commands won’t help. Would I get around it by getting the player’s location and determining if it’s to the right or left of it? I suppose if I wanted to make a general enemy do this too I’d do the same thing but with getting the location of the next waypoint? I was hoping there was an easier way than that. I’m new to blueprints so I’m not sure what nodes to use. There seems to be a lot of nodes that do the same thing. For instance, for getting the location of something, especially a player character, you have options for getting the controller, getting the player character, or getting the player pawn, or the player camera manager, among a whole slew of other things. It’s rather confusing.