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

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

概述我目前正在Unity3d开发一款空气曲棍球比赛.我遇到的问题是,当玩家试图过快地击中冰球时,玩家最终会通过冰球,因此没有碰撞.如果玩家保持静止并且冰球击中玩家或者玩家以缓慢的速度击中冰球,则游戏将按照预期完美地运行. 玩家有一个使用胶囊对撞机进行连续碰撞检测的刚体.冰球还具有连续动态碰撞检测的刚体和带凸面的网格对撞机. 我尝试将固定时间步长设置为0.01,但没有效果.这是玩家运动的脚本: void 我目前正在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 playerif(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.

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

总结

以上是内存溢出为你收集整理的c# – 空气曲棍球比赛 – 如果移动得太快,球员蝙蝠会经过冰球全部内容,希望文章能够帮你解决c# – 空气曲棍球比赛 – 如果移动得太快,球员蝙蝠会经过冰球所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1248041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存