Box collision with changing Box size

Hi there!

I have a real big problem solving how I can make sure my sprite does not get stuck when it runs into a wall and during the animation the sprites collision box has changed in size to fit the new frame. (different sized frames)

From the start the whole animation system was based on the sdltutorials.com's animation tutorial, but then i expanded on it and created framesets with frames.

The collision basically is pretty simple, it tries to check if the new position the player wants to move to is valid, and then moves closer to that position until it hits it. Now this creates the problem, say if the player is 5px from a wall and the col box is 5px from the wall, now the sprite changes frame and get a 6px bigger col box. Now the player gets stuck in the wall. How should i solve this? Tried a few things but I'm starting to run low on ideas.

Thanks
Last edited on
Anyone ? I am desperate :/ No need for big code chunks, just need a push in the right direction or ideas.
Many games works fine without changing the collision box size. It's often not necessary to change the collision box size for small changes in frame size.

In a game like Super Mario Bros. the collision box size only has to change when you duck or when you eat a mushroom. During the walk/run animation the collision size never change.

I don't know what's the best way to handle changing collision box size is. I guess it depends on your needs and how you have things set up. Here are some ideas.

1. Every time the collision box size change, do collision detections against walls. If there is a collision, move object outside of the wall. This is probably more suitable if the collision box size doesn't change very often.

2. Make it possible to move out from a wall by checking if the object is moving towards the wall centre or not.

3. Do collision detection each update and if there is a collision move the object a small distance away from the wall centre.
Thanks for the reply. Well this "game" (which isn't really a game, just game focused to try and learn as much as possible and keeping it fun) uses different sized sprites for almost every frame in a frameset, I have that working, but it´s just the collision that sucks. Either the colbox is too small so the char looks like it has its head inside the wall, or it´s too big so it looks like the head is 10px from the wall.

I´m not sure how to implement your suggestions since the collision system in place right now is taken from a tutorial. If the colbox has the same size all the time then there is no problem, since it never really collides with the wall. It checks where the next move is, if there is a wall there it moves closer and closer till it´s there and then stops. It doesn't move into the wall and the pushes out of it.

:/

Maybe I'm not good enough to solve this, but then again I managed to create sprite animation with different sized frames, and I thought that would never happen.

If anyone feels they can clarify anything, please do.
Topic archived. No new replies allowed.