Hi, the topic basicly is the question:
what would be the c++ code i have to use in my AnimInstance to have the same functionality as the “Calculate Direction” node? Getting the speed was really no issue…direction seems a bit more complicated.
Do i have to use my input axis values for that?
My character has two movement modes. One is simple by facing the direction he is moving.
Second one he is moving in the direction as by input but facing towards a cursor for aiming with a gun.
Thank you in advance
After some googeling (which i could have done better before asking here) i found the solution.
So for anybody who wants to calculate speed and direction in C++ instead using the AnimBlueprint, here is my code.
.h file:
.cpp file:
AnimBP:
You mean the code I used?
UKismetAnimationLibrary::CalculateDirection();
if you are using a later version of UE CalculateDirection is deprecated so you have to use:
MovementDirecction = UKismetAnimationLibrary::CalculateDirection(Velocity, Main->GetActorRotation);
But before you can use UKismetAnimationLibrary you have to add AnimGraphRuntime dependency module to you Build.cs.
PrivateDependencyModuleNames.AddRange(new string { “AnimGraphRuntime” });
I am using UE 5.4 and I got the CalculateDirection is deprecated message,
The KismetAnimationLibrary.h header file refers to the AnimGraphRuntime module, which may not be included in your project by default.
Open your project’s .Build.cs file and add AnimGraphRuntime to the PublicDependencyModuleNames or PrivateDependencyModuleNames section:
I had issue with the include for this and realize that my AnimGraphRuntime modules was saved all the way in
#include "Runtime/AnimGraphRuntime/Public/KismetAnimationLibrary.h"
Might wanna check your Solution Explorer and see exactly where the module dependency is saved and adjust the include accordingly !
This would be enough:
#include "KismetAnimationLibrary.h"
I think you have something wrong configured in your IDE