Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

使用 RigidBody


刚体是由物理引擎直接控制的物体,用于模拟物体的的物理行为。为了定义刚体的形状,必须为其指定一个或多个 Shape3D 对象。注意,设置这些形状的位置将影响物体的质心。


A rigid body's behavior can be altered by setting its properties, such as mass and weight. A physics material needs to be added to the rigid body to adjust its friction and bounce, and set if it's absorbent and/or rough. These properties can be set in the Inspector or via code. See RigidBody3D and PhysicsMaterial for the full list of properties and their effects.

有几种方法可以控制刚体的运动, 这取决于你的应用程序.

If you only need to place a rigid body once, for example to set its initial location, you can use the methods provided by the Node3D node, such as set_global_transform() or look_at(). However, these methods cannot be called every frame or the physics engine will not be able to correctly simulate the body's state. As an example, consider a rigid body that you want to rotate so that it points towards another object. A common mistake when implementing this kind of behavior is to use look_at() every frame, which breaks the physics simulation. Below, we'll demonstrate how to implement this correctly.

你不能使用 set_global_transform()look_at() 方法并不意味着你不能完全控制一个刚体. 相反, 你可以通过使用 _integrate_forces() 回调来控制它. 在这个方法中, 你可以添加 , 应用 冲量 , 或者设置 速度 , 以实现你想要的任何运动.

“look at”方法

As described above, using the Node3D's look_at() method can't be used each frame to follow a target. Here is a custom look_at() method called look_follow() that will work with rigid bodies:

extends RigidBody3D

var speed: float