我正在使用子弹制作游泳池模拟器,需要准确模拟人类可能的镜头.为了找到应用于母球的冲动,我使用了物体球,口袋中心和母球的位置.
常见拍摄场景http://www.poolplayers.com/wp-content/uploads/2013/03/372-TangentLine-2.jpg
在母球的运动路径类似于物体球(180度附近的击打角度)的情况下,一切正常并且物体球落入口袋中.但似乎镜头路径的角度越大,我产生的脉冲的误差范围就越大.我已经尝试了很多东西来解决这个问题:调整球的碰撞余量,扩大世界范围,关闭摩擦力和恢复原状以及许多其他因素似乎没有改变这种行为.
以下是我的代码的相关部分:
//assume p = pocket center, b = object ball center, c = cue ball center
//first find the position of the ghost ball, ie the target point of collision for the cue ball
btVector3 ghostPos = b+(b-p).normalize()*(2.0f*BALL_RADIUS);
//then use the normal between the ghostball and cue ball as the impulse, scaled by the shots total distance
btVector3 cueImpulse = (ghostPos-c).normalize()*((p.distance(b)+ghostPos.distance(c))*HIT_RATIO);
//finally apply the impulse to the cueball's center of mass (using general form of applyImpulse to …
Run Code Online (Sandbox Code Playgroud) 我用Java实现了一个游泳池台球游戏,一切正常.这是一个多人游戏,但是,它也应该可以单独玩.为此,我试图实现一个简单的KI.此刻,KI只是随意选择一个方向和一个随机强度的脉冲(不知道正确的英语单词).当然,这个AI非常差,不太可能挑战玩家.
所以我想改善KI,但有几个难以解决的问题.首先,我想到只选择最近的球并尝试将其直接放入最近的洞中.这并不是那么糟糕,但如果在其他球之间有其他球,它就不再有效了.另外,这不能解决计算脉冲强度的问题.
那么有什么一般建议吗?还是有什么想法?最佳做法?
我正在尝试计算撞到撞球的角度并预测去向何方。我以为目标球应该在法线方向上移动。但是它的方向却完全不同。
RaycastHit2D hit = Physics2D.CircleCast(cue.position, _radius, dir, 100f, ~(ignoreLayer));
if (hit.collider != null)
{
Debug.DrawRay(hit.collider.transform.position, -1f * hit.normal,
Color.green, Time.fixedDeltaTime);
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
设定速度
rb.velocity = dir * force;
Run Code Online (Sandbox Code Playgroud)
结果:
如何找到确切的移动方向,谢谢
编辑:
我已经尝试过双半径铸造仅在一半时有效..仅当射线在内圆内时