Collision in walls - SFML

Started by
13 comments, last by mypel16000 11 years, 2 months ago

This would work for rectangle collision, but it won't give accurate results for collision vs a circle.

Oops, he was asking about circles and polygons. Yes, my solution could cause problems. I thought it was only rectangles.

Be careful using my solution mypel.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Advertisement

Yes, beernuts, my work is only on rectangles


.

Oops, he was asking about circles and polygons. Yes, my solution could cause problems. I thought it was only rectangles.

Be careful using my solution mypel.

I'm just nitpicking here :) but I also have to point out that with your solution, under certain not so difficult to achieve conditions, the player sprite will 'collide' with the wall before he is physically touching it - in the case where the player is, say, 0.2 meter from the wall, and your 'move' takes you 0.3 m into the wall, your collision method would stop the player from moving any closer to the wall and he will remain 0.2m from the wall.

The faster the movement speeds, as well as the slower the position update, the less accurate the results will be. Of course at 60fps and normal human speeds, this isn't an issue, which is why it's just nitpicking :)

Collision detetion is fairly easy and straight forward. It's what to do after you've detected a collision thats the hard part.

The following link is not meant to solve your issues however it should give you a good deal of insight as to how to go about things. It was written with 3D in mind and quite honestly never quite worked right due to floating point errors (maybe later fixed?) however I think it's still worth reading.

As the article is 3D oriented, it can certainly be "dumbed down" for 2D as the principles still apply.

Hope this helps.

http://www.peroxide.dk/download/tutorials/tut10/pxdtut10.html

-=[Megahertz]=-

Yes, the article is quite useful! Thumbs up tp you.

@BeerNuts and Milcho: I'll try combining both your methods and instead of moving -velocity.y or -velocity.x, I will calculate the distance to the edge and correct it, while still separating the axis

That would be a good idea wouldn't it?

If it is, I'll start writing it and then post it here so that everyone can see.

This topic is closed to new replies.

Advertisement