加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 空气曲棍球比赛 – 如果移动得太快,球员蝙蝠会经过冰球

发布时间:2020-12-15 08:16:41 所属栏目:百科 来源:网络整理
导读:我目前正在Unity3d开发一款空气曲棍球比赛.我遇到的问题是,当玩家试图过快地击中冰球时,玩家最终会通过冰球,因此没有碰撞.如果玩家保持静止并且冰球击中玩家或者玩家以缓慢的速度击中冰球,则游戏将按照预期完美地运行. 玩家有一个使用胶囊对撞机进行连续碰撞
我目前正在Unity3d开发一款空气曲棍球比赛.我遇到的问题是,当玩家试图过快地击中冰球时,玩家最终会通过冰球,因此没有碰撞.如果玩家保持静止并且冰球击中玩家或者玩家以缓慢的速度击中冰球,则游戏将按照预期完美地运行.

玩家有一个使用胶囊对撞机进行连续碰撞检测的刚体.冰球还具有连续动态碰撞检测的刚体和带凸面的网格对撞机.

我尝试将固定时间步长设置为0.01,但没有效果.这是玩家运动的脚本:

void ObjectFollowCursor()
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    Vector3 point = ray.origin + (ray.direction * distance);

    Vector3 temp = point;
    temp.y = 0.2f; // limits player on y axis

    cursorObject.position = temp;
}

这是冰球与玩家碰撞时的代码:

// If puck hits player
if(collision.gameObject.tag == "Player")
{
    Vector3 forceVec = this.GetComponent<Rigidbody>().velocity.normalized * hitForce;
    rb.AddForce(forceVec,ForceMode.Impulse);
    Debug.Log ("Player Hit");
}

任何帮助将非常感激.谢谢.

解决方法

你是正确的尝试连续碰撞检测(CCD).存在一些约束(特别是在这种情况下,您希望使用具有两个移动对象的CCD而不是一个移动对象和一个静态对象),但它是针对这种情况设计的. The Rigidbody documentation进入这些限制:

Set the collision detection mode to Continuous to prevent the
rigidbody from passing through any static (ie,non-rigidbody)
MeshColliders. Set it to Continuous Dynamic to also prevent the
rigidbody from passing through any other supported rigidbodies with
collision detection mode set to Continuous or Continuous Dynamic.
Continuous collision detection is supported for Box-,Sphere- and
CapsuleColliders.

总而言之,冰球和桨叶都需要设置为连续动态,并且都需要是Box,Sphere或Capsule Colliders.如果您可以使这些约束适用于您的游戏,您应该能够连续碰撞检测,而无需自己编写.

有关Unity的CCD的重复说明:

Note that continuous collision detection is intended as a safety net
to catch collisions in cases where objects would otherwise pass
through each other,but will not deliver physically accurate collision
results,so you might still consider decreasing the fixed Time step
value in the TimeManager inspector to make the simulation more
precise,if you run into problems with fast moving objects.

但由于您手动指定碰撞反应,这可能不是问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读