How to keep a line from rotating away from the direction the ball is rolling towards?

Here’s a GIF that shows what my ball is doing right now. The green line is a line depicted to the user, telling the user where the ball is going, but in this GIF, the line rotates along with the ball, and not pointing towards the direction the ball is rolling.

This PNG image below shows what I wanted the line to do. The ball should roll on the floor with the line staying stationary and always faces toward the direction in which the ball is rolling. The line should not be affected by the ball’s rotation.


Unfortunately, I don’t know how to keep the line straight. Does anyone know how to do this?

Here is my code. I tried to keep it as SSCCE as possible:

void AFlockObstacle::MoveUpdate(float Delta){
	this->TargetOffset = FVector(100.0f, 0.0f, 0.0f) + this->GetActorLocation();
	this->TargetOffset.Z = 0.0f;
	FRotator Rotation = this->GetActorForwardVector().Rotation();
	this->TargetOffset = Rotation.RotateVector(this->TargetOffset);
	FVector NormalizedTargetOffset(this->TargetOffset);
	FVector SteeringForce = this->Seek(NormalizedTargetOffset);
	this->Velocity += SteeringForce;
	FVector Momentum = this->SphereCollider->BodyInstance.GetBodyMass() * this->Velocity;
	this->SphereCollider->AddForce(Momentum / Delta);

Thanks in advance.

If you don’t want the line affected by the rotation of the ball, then just draw it separately using a simple XYZ offset which you define in code or (better yet) as a UPROPERTY. You can give the line its own local rotation (again via a UPROPERTY or what not) and such, just don’t parent any of your math to the balls rotation.

Does that mean adding a FVector and FRotator as UPROPERTY()s to the class, and make it so the line uses only the FVector and FRotator?

I am currently trying to fix and figure out how a simple hard defined FRotator(0.0f, 45.0f, 0.0f) can still make the line rotate and move like it’s rolling on the side. The line is just using the actor’s location, add offset, and rotated by the fixed FRotator for the end position.