What collision detection method to use with hand drawn surface?

孤街浪徒 提交于 2020-01-15 06:26:42

问题


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:

  1. 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.

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!