문제

I have some collision detection working when my player hits an object. But this only works when my players x & y co-ordinates hit my marker (which is the centre of my character).

Would making a method returning a vector of all of the coordinates that the players texture cover work and what is the best way to implement this?

This is being done in c++ creating a top down game

올바른 솔루션이 없습니다

다른 팁

There are many ways to do it, most simply is probably(depending on you use of classes etc). This is the simplest, but no where near the best, or infact very good at all. This way means changing your "marker" to the bottom left of the rectangle.

void collisions()
{
    //check if the x-coord is between the furthest left and furthest right x coords
    if(rect.Getx() > someObject.Getx() && rect.Getx() < someObject.Getx() + someObject.GetWidth())
    {
        rect.SetMoveSpeed(0);
    }
    if(rect.Gety() > someObject.Gety() && rect.Gety() < someObject.Gety() + someObject.GetHeight())
    {
        rect.setMoveSpeed(0);
    }

}

You would then have to set the move speed to normal when it is not colliding. That could be done with an else after each if, setting the move speed again. This is a quick fix and is not recommended for use in a game you plan to distribute anywhere.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top