浏览代码

Update example code for Godot 4 in Using RigidBody (#6215)

nerdbeard 2 年之前
父节点
当前提交
f5b3a2fab2
共有 1 个文件被更改,包括 5 次插入5 次删除
  1. 5 5
      tutorials/physics/rigid_body.rst

+ 5 - 5
tutorials/physics/rigid_body.rst

@@ -38,15 +38,15 @@ Here is a custom ``look_at()`` method that will work reliably with rigid bodies:
 
     func look_follow(state, current_transform, target_position):
         var up_dir = Vector3(0, 1, 0)
-        var cur_dir = current_transform.basis.xform(Vector3(0, 0, 1))
+        var cur_dir = current_transform.basis * Vector3(0, 0, 1)
         var target_dir = (target_position - current_transform.origin).normalized()
         var rotation_angle = acos(cur_dir.x) - acos(target_dir.x)
 
-        state.set_angular_velocity(up_dir * (rotation_angle / state.get_step()))
+        state.angular_velocity = up_dir * (rotation_angle / state.step)
 
     func _integrate_forces(state):
-        var target_position = $my_target_spatial_node.get_global_transform().origin
-        look_follow(state, get_global_transform(), target_position)
+        var target_position = $my_target_spatial_node.global_transform.origin
+        look_follow(state, global_transform, target_position)
 
  .. code-tab:: csharp
 
@@ -70,6 +70,6 @@ Here is a custom ``look_at()`` method that will work reliably with rigid bodies:
     }
 
 
-This method uses the rigid body's ``set_angular_velocity()`` method to rotate the body. It first calculates the difference between the current and desired angle and then adds the velocity needed to rotate by that amount in one frame's time.
+This method uses the rigid body's ``angular_velocity`` property to rotate the body. It first calculates the difference between the current and desired angle and then adds the velocity needed to rotate by that amount in one frame's time.
 
 .. note:: This script will not work with rigid bodies in *character mode* because then, the body's rotation is locked. In that case, you would have to rotate the attached mesh node instead using the standard Spatial methods.