Rotating Character towads the object it is interacting with

How would you handle character orientation while interacting with an object?
if I am not perfectly in front of the object I need to interact with, but want the character to place itself rigth in front of the interactable before doing whatever animation the interaction needs, how would you do it?

For example: if I am interacting with the entrance to a passage to crawl inside, how would you handle the movement in C++ so that my Chracater, before crawling in, sets itself right in front of the Actor that starts the interaction after I press whatever commands it needs?

I hope it makes sense.

1 Like

image

2 Likes

Tried it but it seems it’s not what I need.

But thank you! I’ll keep it in mind!

Extremely case-specific. You probably want a target point with a location and rotation associated with your object that the player or NPC moves to before performing the crawl. Should be set up in level where needed.

We use this type of thing commonly for where NPCs have to go pick up or drop objects. They move and align properly to the target point and then do the pickup / drop.

1 Like

Solved it by doing this:

I combined @eldany.uy and @Shmoopy1701 advices.

void AFPSCharacter::OrientTowardsTarget(AEntrance* Target)
{
	if (Target)
	{
		FVector TargetLocation = Target->GetActorLocation();

		FVector TargetForward = Target->GetActorForwardVector();

		FVector DesiredPosition = TargetLocation + (TargetForward * Distance);

		SetActorLocation(DesiredPosition);

		FRotator TargetRotation = UKismetMathLibrary::FindLookAtRotation(GetActorLocation(), TargetLocation);

		TargetRotation.Roll = 0.0f;
		TargetRotation.Pitch = 0.0f;

		GetController()->SetControlRotation(TargetRotation);
	}
}
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.