手绘表面使用什么碰撞检测方法?手绘、检测方法、表面

2023-09-06 10:33:45 作者:叼辣条闯世界

我有一个月球着陆器类型的游戏.我不使用任何物理引擎.如果您不使用推进器,我的着陆器会不断下降并最终降落在地面上.地面是手绘的,它不是一条线,更像曲线,土地可以是任何形状或颜色.如何正确使用碰撞检测及其结果?

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?

推荐答案

这取决于你想做什么.我会推荐以下之一:

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