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);
NormalizedTargetOffset.Normalize();
FVector SteeringForce = this->Seek(NormalizedTargetOffset);
this->Velocity += SteeringForce;
FVector Momentum = this->SphereCollider->BodyInstance.GetBodyMass() * this->Velocity;
this->SphereCollider->AddForce(Momentum / Delta);
}
Thanks in advance.