Hi everyone,
I'm trying to make proper collisions in my game, but unfortunately they don't work.
void APlayerController::MoveLeft(const float& DeltaTime)
{
sf::Vector2f PawnLocation = Pawn->GetLocation(); //Get previous location
Pawn->SetLocation(Pawn->GetLocation().x - Velocity * DeltaTime, Pawn->GetLocation().y); //Move sprite
dynamic_cast<APlayer*> (Pawn)->SetDirection(EDirection::ELeft);
if (dynamic_cast<APlayer*> (Pawn)->IsColliding())
{
Pawn->SetLocation(PawnLocation); // if there's collision move back sprite
}
}
This is example movement method from my player's class.
bool APlayer::IsColliding()
{
auto Tiles = GGame::Instantiate().GetLevel()->GetCollidableTiles();
for (auto Tile : Tiles)
{
auto TempTile = dynamic_cast<ATile*> (Tile);
if (Tile)
{
if (this->GetCollider().intersects(TempTile->GetCollider()))
{
return true;
}
}
}
return false;
}
And this is method to check if player is colliding with any collidable tile on my map.
Any ideas what is wrong?