Min collisions - BKP Game journal - GameDev.net

Min collisions

posted in BKP Game journal
Published March 29, 2018
Advertisement

 

Hey,
I have been busy lately, still learning more about OpenGL and of course my work. I should accelerate a little bit now.

Now I added a collision engine, very basic at the moment. it is about detecting if a point is inside a platform rotated or not. plus solve the deformation on rotations in the previous entry.  Also updated the math functions.

Collision:

Nothing very fancy, just check if the point is inside the bouncing box if the platform is not rotated it will return collision detected. if the platform has rotated then the point will be rotated opposite angle to go back to the previous situation and do the same check.


int bkp_physics_inPlatform2D(BKP_VEC3 point, BKP_Entity_Platform * p)
{
    float X = point.x;                                                                                                                                                                                                                                                          
    float Y = point.y;

    if(X > p->bbox.x && X < p->bbox.x + p->bbox.w && Y > p->bbox.y && Y < p->bbox.y + p->bbox.h)
    {   

        if( p->isrotated == BKP_TRUE)
        {   
            X = X - p->rotate.center.x;
            Y = Y - p->rotate.center.y;

            float x =  p->rotate.center.x + X * p->cos_a     - Y * (- p->sin_a);
            float y =  p->rotate.center.y + X * (- p->sin_a) + Y * p->cos_a;

            if(x > p->x && x < p->x + p->w && y > p->y && y < p->y + p->h)
                return BKP_TRUE;
        }   
        else
            return BKP_TRUE;
    }   

    return BKP_FALSE;
}

Notice that the cos and sin are precalculated each team the platform if it rotates only. avoiding to use too much expensive cos and sin.

You can see on the video the mouse cursor becoming red each time it is inside a platform.You can also see on the sprite 8 points that I will be used to make the collision detection.

Gravity:

on this other video, I activated gravity. but no collision. it is possible to jump in the air to test the effect of jump

 

Well, that's all done for now. I will unify collision detection and gravity, add some penetration resolution and we will see a first step done. next step will be more about game play.

 

 

2 likes 4 comments

Comments

Rutin

Nice job! Glad to see you're progressing!

March 29, 2018 04:26 PM
lilington

Thanks, the next entry will be sooner

March 29, 2018 11:34 PM
Rutin
On 3/29/2018 at 5:34 PM, lilington said:

Thanks, the next entry will be sooner

How's everything going? :) 

April 19, 2018 01:09 AM
lilington

Oops , I just noticed it. haha. been busy with my feeding me job and the game. I just posted something new. you can have a look at the next entry. thanks

 

May 07, 2018 11:41 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement