Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Anthis

Pages: [1]
1
Graphics / Problems with collision [solved]
« on: June 17, 2019, 08:32:05 am »
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?

Pages: [1]