手绘表面使用哪种碰撞检测方法? [英] What collision detection method to use with hand drawn surface?

查看:78
本文介绍了手绘表面使用哪种碰撞检测方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个月球着陆型游戏。我没有使用任何物理引擎。
如果您不使用推进器,我的着陆器会继续下降,并最终着陆。地面是手绘的,它不是直线,更像曲线,并且地面可以是任何配置或颜色。
如何正确使用冲突检测及其结果?

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:


  1. 使用物理引擎。他们在那里找东西。您可以创建不同的形状。如果有直线,也可以混合成矩形,或者有很多圆用于曲线等。

  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.

使用您自己的自定义圆碰撞检测器。您用边框大小的圆圈代表着陆器。然后,对于每条手绘线,创建一串代表该线的相邻圆。当您检查着陆器位置时,您基本上只是遍历代表直线的圆并检查碰撞。传入的伪代码

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


这篇关于手绘表面使用哪种碰撞检测方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆