C# Unity 2D 播放器通过 Box Collider
C# Unity 2D Player Goes through Box Collider
我ve got a problem with a player it has RigidBody2D,Box Collider2D
i
已经搜索了 2 天,但没有结果使用了 DontGoThroughThings 和许多其他东西,或者可能做错了什么。我正在制作手机游戏并添加到脚本 Input.touches
foreach (Touch touch in Input.touches)
{
Vector3 newPosition = transform.position;
newPosition.y += touch.deltaPosition.y * speed * Time.deltaTime;
transform.position = newPosition;
}
而且速度很快,当我将手指移动到快速物体时,物体直接离开相机视野并且他没有与对撞机发生碰撞
抱歉英语不好
谢谢你的建议
如果需要更多信息,我会提供详细信息。
可能的问题是您的对象在帧之间移动得太快以至于它完全错过了对撞机。您应该将对象可以达到的最大速度限制在某个合理的范围内,而不是直接使用 touch.deltaPosition.y
。像这样:
foreach (Touch touch in Input.touches)
{
Vector3 newPosition = transform.position;
newPosition.y += Mathf.Clamp(touch.deltaPosition.y * speed, MIN_SPEED, MAX_SPEED) * Time.deltaTime;
transform.position = newPosition;
}
这是离散物理模拟的常见问题。
Copy/paste 来自这个 link 以防网站死亡:
This phenomenon is called “tunneling”. Tunneling comes up when an
object is going so fast that the new updated position does not
intersect with the object it was heading towards.
It is all really about scale. Tunneling will only occur if an object
is moving fast enough so that it can move the complete length of the
shortest width of another object in the time quantum of the
simulation.
There are physics simulation libraries that perform continuous
collision detection (CCD) which will figure out if two objects
collided at any point within the simulation frame. Usually this is
accomplished by creating a new collision shape that has a volume which
contains all the space that the moving object occupied throughout the
time quantum. It then tries to figure out the intersection of the
movement volumes with other objects and then looks even closer to see
if the both objects existed at the intersection of their collision
volumes at the same time.
我ve got a problem with a player it has RigidBody2D,Box Collider2D
i
已经搜索了 2 天,但没有结果使用了 DontGoThroughThings 和许多其他东西,或者可能做错了什么。我正在制作手机游戏并添加到脚本 Input.touches
foreach (Touch touch in Input.touches)
{
Vector3 newPosition = transform.position;
newPosition.y += touch.deltaPosition.y * speed * Time.deltaTime;
transform.position = newPosition;
}
而且速度很快,当我将手指移动到快速物体时,物体直接离开相机视野并且他没有与对撞机发生碰撞
抱歉英语不好 谢谢你的建议 如果需要更多信息,我会提供详细信息。
可能的问题是您的对象在帧之间移动得太快以至于它完全错过了对撞机。您应该将对象可以达到的最大速度限制在某个合理的范围内,而不是直接使用 touch.deltaPosition.y
。像这样:
foreach (Touch touch in Input.touches)
{
Vector3 newPosition = transform.position;
newPosition.y += Mathf.Clamp(touch.deltaPosition.y * speed, MIN_SPEED, MAX_SPEED) * Time.deltaTime;
transform.position = newPosition;
}
这是离散物理模拟的常见问题。
Copy/paste 来自这个 link 以防网站死亡:
This phenomenon is called “tunneling”. Tunneling comes up when an object is going so fast that the new updated position does not intersect with the object it was heading towards.
It is all really about scale. Tunneling will only occur if an object is moving fast enough so that it can move the complete length of the shortest width of another object in the time quantum of the simulation.
There are physics simulation libraries that perform continuous collision detection (CCD) which will figure out if two objects collided at any point within the simulation frame. Usually this is accomplished by creating a new collision shape that has a volume which contains all the space that the moving object occupied throughout the time quantum. It then tries to figure out the intersection of the movement volumes with other objects and then looks even closer to see if the both objects existed at the intersection of their collision volumes at the same time.