I’m creating a game using pure C++ (some blueprints have been used to change small functionality). The game I’m creating is the player takes control of a ball and has to progress through the level and get through several obstacles.
Along the way there are checkpoints so if the player falls off the level, a trigger volume is activated and I have used SetActorLocation(), I have also tried TeleportTo(), on the ball to teleport it back to the last checkpoint they triggered.
The problem I’m facing is when the ball is teleported back to the checkpoint, it sends the ball high into the air (I believe it actually moves the actor to the location and it bounces off the floor which then sends it flying but it also looks like it comes flying up from the checkpoint). How can I get around this so that the actor is just placed at the desired location? The problem is in the Death.cpp when its sets the actor location.
When the player goes over a checkpoint Respawn.cpp is triggered.
Respawn.cpp
void URespawn::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (!Trigger) { return; }
if (!Ball) { return; }
// If Actor is on checkpoint,
if (Trigger->IsOverlappingActor(TriggeringActor)) {
Ball->SetSpawnLocation(GetOwner()->GetActorLocation()); // Set the new spawn location
}
}
When the player falls off the edge Death.cpp is called.
Death.cpp
void UDeath::PlayerDeath()
{
if (Ball == nullptr) { return; } // Reference to pawn
if (Lives == 0) {
UGameplayStatics::OpenLevel(this, FName("GameOver")); // If player has died too many times, open Game Over screen
}
else {
Ball->SetActorLocation(Ball->GetSpawnLocation()); // Spawn player at checkpoint (**This is where the problem is**)
Lives--; // Remove a life
}
}
The pawn gets the location of the checkpoint + 70.f on the Z axis to prevent collision
TP_RollingBall.cpp // Pawn
void ATP_RollingBall::SetSpawnLocation(FVector Location)
{
SpawnLocation = Location;
}
FVector ATP_RollingBall::GetSpawnLocation()
{
return SpawnLocation + FVector(0.f, 0.f, 70.0f);
}
Thanks in advance.