I have a character, and when the velocity is greater than 0, the camera controls the character’s rotation. However, when the velocity is equal to 0, I can rotate the camera around the character. But, if I’m looking from behind the character and press ‘W’ while the velocity is 0, the character abruptly turns in a fraction of a second. How can I make the character turn with animation first and then start moving?
How are you setting the rotation when moving? If you’re directly setting it in tick or something, try having the input axis event for moving set UseControllerDesiredRotation true on the character movement component instead. Then on the release/complete event for axis set that back to false.
With UseControllerDesiredRotation set, you can tweak the rotation rate in the movement comp to smooth the turn a bit.
Is there a C++ solution? I use this code for movement:
void ASTUBaseCharacter::MoveForward(float amount)
{
AddMovementInput(GetActorForwardVector(), amount);
}
void ASTUBaseCharacter::MoveRight(float amount)
{
AddMovementInput(GetActorRightVector(), amount);
}
void ASTUBaseCharacter::LookUp(float amount)
{
AddControllerPitchInput(amount);
}
void ASTUBaseCharacter::TurnAround(float amount)
{
AddControllerYawInput(amount);
}
and for camera, when Velocity = 0, this one:
void ASTUBaseCharacter::IsActorStanding(FVector vel)
{
double velocity = vel.Length();
if (velocity == 0)
{
ASTUBaseCharacter::bUseControllerRotationYaw = false;
}
else
{
ASTUBaseCharacter::bUseControllerRotationYaw = true;
}
}
Here is the video with the actual issue - Unreal Engine 5 2023.10.30 - 23.06.35.03.mp4 - VEED
For code, I think you’d want to set bUseControllerDesiredRotation = true on the charcter movement component rather than use yaw.
CharacterMovement->bUseControllerDesiredRotation = true;
I think. My c++ is rather rusty.
Use controller yaw directly copies the rot from the controller, IIRC, hence the fast turns. Whereas Use Desired interps towards it based on the rotation rate.
Video says it isn’t ready yet, so I can’t see what’s happening.
“Thank you! This is exactly what I needed. Could you also give me some guidance on how to set up specific turning animations for this?”
If you’re using a 2D blendspace with standard speed and direction axes driving it, the easiest way to animate it is with some foot shuffling turn in place animations to the left and right of speed 0 postition of the blendspace. Then in anim bp, when character’s velocity = 0, feed the yaw of the rotation delta between the current and previous frame’s rotation to the direction.
Obviously not the most efficient way to do it, but the relevant part of event graph in my anim bp looks like this:
The divisor leading into the yaw delta set node is coming from delta time on the anim update event.
Probably better to set the yaw delta on the character in code, and select it for direction in anim graph when speed is near 0. Charcter movement comp has a fumction to get last update rot, but I could never get it to work right inside anim bp event graph lol.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.