小编Red*_*hft的帖子

2D连续碰撞检测

我正在尝试为我的乒乓游戏实现简单的连续碰撞检测,但我不确定我是否正在实施或理解这一点.AFAIR连续碰撞检测用于快速移动的物体,可以通过另一个物体绕过正常的碰撞检测.

所以我试过的是因为我所拥有的唯一一个快速移动的物体是一个球,我只需要球的位置,它的移动速度,以及我们所比较的物体的位置.

从这里我认为最好是,例如如果球的移动速度表明它向左移动,我会将它的最左边的边界与另一个物体的最右边界相比较.从这里我将通过将移动速度添加到球的最左边界并逐步比较以确保它比其他对象的右边界更大.这表明没有左右碰撞.

我有一些工作,但不幸的是,球开始正常弹跳一段时间然后它就好像它没有任何东西击中桨.

我有点失落,任何帮助将不胜感激!

static bool CheckContinuousCollision(PActor ball, PRect ballRect, PActor other, PRect otherRect)
{
    PVector ballMoveSpeed;
    int ballXLimit;
    int ballYLimit;

    ballMoveSpeed = ball.moveSpeed;

    // We are moving left
    if ( sgn(ball.moveSpeed.x) < 0 )
    {
        ballXLimit = std.math.abs(ballMoveSpeed.x) / 2;

        for ( int i = 0; i <= ballXLimit; i++ )
        {

                if ( ballRect.Left < otherRect.Right && otherRect.Left < ballRect.Left)
            {
                return true;
            }

            ballRect.Left -= i;
        }
    }

            //We are moving right
    if ( sgn(ball.moveSpeed.x) > …
Run Code Online (Sandbox Code Playgroud)

math 2d collision-detection

6
推荐指数
1
解决办法
1253
查看次数

A*PathFinding性能不佳

调试几个小时后,算法似乎正在运行.现在检查它是否有效我在while循环退出时检查结束节点位置到currentNode位置.到目前为止,值看起来是正确的 问题是,我离NPC越远,当前静止,性能越差.它达到了游戏无法播放不到10 fps的程度.我目前的PathGraph是2500个节点,我相信它非常小,对吧?关于如何提高绩效的任何想法?

struct Node
{
    bool walkable;      //Whether this node is blocked or open
    vect2 position;     //The tile's position on the map in pixels
    int xIndex, yIndex; //The index values of the tile in the array
    Node*[4] connections; //An array of pointers to nodes this current node connects to
    Node* parent;
    int gScore;
    int hScore;
    int fScore;
}

class AStar
{
    private:
    SList!Node openList;    //List of nodes who have been visited, with F scores but not processed
    SList!Node closedList; …
Run Code Online (Sandbox Code Playgroud)

artificial-intelligence d a-star path-finding

5
推荐指数
1
解决办法
707
查看次数

插入关联数组?

我现在正在玩关联数组,我似乎无法弄清楚如何向数组中添加其他对象.我尝试过插入,但它不能识别这两个参数.

另外,如果我这样做会产生错误:

Node[bool] test;

Node node;

Node[bool] temp = [ false:node ];

test ~= temp;


//Error 1   Error: cannot append type Node[bool] to type
//Node[bool]    C:\Users\CP\Documents\Visual Studio
//2010\Projects\D\STDS\NPC.d    256 
Run Code Online (Sandbox Code Playgroud)

这是否意味着你不能在关联数组上使用append运算符?

d

2
推荐指数
1
解决办法
199
查看次数

碰撞检测并保持物体上的动量

我一直在实施各种形式的简单碰撞检测,结果各不相同.我有一个相当不错的碰撞检测工作版本,但有些奇怪的行为让我无法解决.

仅供参考,我正在做一个简单的乒乓球比赛,并试图改善碰撞.我得到的问题是球在顶部或底部碰撞桨.在这些情况下,球在桨的上方(或下方)盘旋并且不移动.我猜这是因为我正在检查碰撞以及我如何改变球的移动速度.

我想实现一种区分顶部/底部和左/右碰撞的方法,但这是唯一可行的方法:

static void CheckCollision(PActor object1, PActor object2, PInput pinput)
{
    if ( CheckObjectCollision( object1, object2 ) )
    {
        AdjustMoveSpeed( object1, object2, pinput );
    }
}



static bool CheckObjectCollision(PActor object1, PActor object2)
{
    int object1LeftBound = object1.position.x;
    int object1RightBound = object1.position.x + object1.actorTextureXSize;
    int object1TopBound = object1.position.y;
    int object1BottomBound = object1.position.y + object1.actorTextureYSize;

    int object2LeftBound = object2.position.x;
    int object2RightBound = object2.position.x + object1.actorTextureXSize;
    int object2TopBound = object2.position.y;
    int object2BottomBound = object2.position.y + object2.actorTextureYSize;

    if ( object1RightBound < object2LeftBound ) …
Run Code Online (Sandbox Code Playgroud)

math sdl d

1
推荐指数
1
解决办法
418
查看次数