问题
I have a lunar lander type game. I don't use any physics engines. My lander keeps falling if you do not use thruster and eventually lands on the ground. Ground is hand drawn, it is not a line, more like curve, and the land can be of any configuration or color. How do I properly use collision detection and its results?
回答1:
Well it depends on what you want to do. I would recommend one of the following:
Use physics engines. They are there for something. You could create different shapes what was drawn. You could mix in a rectangle if theres a straight line, or a lot of circles for curves, etc.
Use your own custom circle collision detector. You represent the lander with a bounding box sized circle. Then, for each of the handdrawn lines, create a bunch of adjacent circles representing the line. When you check your lander position, you are just basically looping through the circles representing the lines and checking for collisions. Incoming pseudocode
for (CollisionCircle* circle in collisions) { if (circle.collidesWith(lander.collisionCircle)) { // 1. Calculate edge distance from lander to circle (position + radius distance) // 2. Remove distance from lander position to fix position. } }
来源:https://stackoverflow.com/questions/11782211/what-collision-detection-method-to-use-with-hand-drawn-surface