浏览代码

fix: Improve and update Physics Jitter content

Vaclav Elias 1 年之前
父节点
当前提交
a9593da811
共有 3 个文件被更改,包括 50 次插入40 次删除
  1. 45 38
      en/manual/physics/fix-physics-jitter.md
  2. 3 2
      en/manual/physics/index.md
  3. 2 0
      en/manual/toc.yml

+ 45 - 38
en/manual/physics/fix-physics-jitter.md

@@ -1,97 +1,103 @@
-# Fix Physics Jitter
+# Fix physics jitter
 
 
 <span class="badge text-bg-primary">Beginner</span>
 <span class="badge text-bg-primary">Beginner</span>
 <span class="badge text-bg-success">Programmer</span>
 <span class="badge text-bg-success">Programmer</span>
 
 
-In Stride there is no default smoothing applied to Entities that are attached to physics entities. This can cause a noticable jitter especially if you have the camera attached to a character component.
-In this tutorial we will look at whats needed to add smoothing to an entity through a SyncScript.
+In Stride, there is no default smoothing applied to entities that are attached to physics entities. This can cause noticeable jitter, especially if the camera is attached to a character component.
 
 
->[!Note]
->You can also decrease the `Fixed Time Step` in the physics configuration, for example change it from `0.016667` to `0.008` for more accurate physics but this will be more expensive on the CPU.
+In this tutorial, we will explore how to add smoothing to an entity using a SyncScript.
+
+> [!Note]
+> You can also decrease the `Fixed Time Step` in the physics settings configuration to achieve more accurate physics simulations. For example, changing it from `0.016667` to `0.008` will increase accuracy but at the cost of higher CPU usage.
+
+## Code to handle smoothing between two entities
+The following code is all that's needed to smoothly attach two entities. Ensure that you unparent the entity you are trying to smooth, otherwise the transform processor will override this script.
 
 
-## Code to handle smoothing between 2 entities
-This should be all thats needed to attach 2 entities together. Make sure that you unparent the entity you are trying to smooth or else the transofrm processor will override this script.
 ```cs
 ```cs
 [ComponentCategory("Utils")]
 [ComponentCategory("Utils")]
 [DataContract("SmoothFollowAndRotate")]
 [DataContract("SmoothFollowAndRotate")]
 public class SmoothFollowAndRotate : SyncScript
 public class SmoothFollowAndRotate : SyncScript
 {
 {
-	public Entity EntityToFollow { get; set; }
-	public float Speed { get; set; } = 1;
+    public Entity EntityToFollow { get; set; }
+    public float Speed { get; set; } = 1;
 
 
-	public override void Update()
-	{
-		var deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds;
-		var currentPosition = Entity.Transform.Position;
-		var currentRotation = Entity.Transform.Rotation;
+    public override void Update()
+    {
+        var deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds;
+        var currentPosition = Entity.Transform.Position;
+        var currentRotation = Entity.Transform.Rotation;
 
 
-		var lerpSpeed = 1f - MathF.Exp(-Speed * deltaTime);
+        var lerpSpeed = 1f - MathF.Exp(-Speed * deltaTime);
 
 
-		EntityToFollow.Transform.GetWorldTransformation(out var otherPosition, out var otherRotation, out var _);
+        EntityToFollow.Transform.GetWorldTransformation(out var otherPosition, out var otherRotation, out var _);
 
 
-		var newPosition = Vector3.Lerp(currentPosition, otherPosition, lerpSpeed);
-		Entity.Transform.Position = newPosition;
+        var newPosition = Vector3.Lerp(currentPosition, otherPosition, lerpSpeed);
+        Entity.Transform.Position = newPosition;
 
 
-		Quaternion.Slerp(ref currentRotation, ref otherRotation, lerpSpeed, out var newRotation);
-		Entity.Transform.Rotation = newRotation;
-	}
+        Quaternion.Slerp(ref currentRotation, ref otherRotation, lerpSpeed, out var newRotation);
+        Entity.Transform.Rotation = newRotation;
+    }
 }
 }
 ```
 ```
 
 
 ## Example Usage
 ## Example Usage
-For this example we will modify the First Person Shooter Template.
-
-Step 1: Detach the camera from the Physics entity
 
 
-Step 2: Remove the FPS camera script from the camera
+This example demonstrates modifications to the **First Person Shooter** Template to integrate smooth camera movement.
 
 
-Step 3: create a new entity as a child to the character body
+1. Detach the camera from the physics entity.
+2. Remove the FPS camera script from the camera.
+3. Create a new entity as a child of the character body.
+4. Add the FPS script to the new entity.
+5. Adjust any code that directly references the `CameraComponent` to reflect these changes.
 
 
-Step 4: Add the FPS script to the new entity
+### PlayerInput.cs
 
 
-Step 5: change the following code since they reference the CameraComponent directly
+Change
 
 
-### PlayerInput.cs
-change
 ```cs
 ```cs
 public CameraComponent Camera { get; set; }
 public CameraComponent Camera { get; set; }
 ```
 ```
 to
 to
+
 ```cs
 ```cs
 public Entity Camera { get; set; }
 public Entity Camera { get; set; }
 ```
 ```
 
 
----
-
 ### Utils.cs
 ### Utils.cs
-change
+
+Change
+
 ```cs
 ```cs
 CameraComponent camera
 CameraComponent camera
 ```
 ```
 to
 to
+
 ```cs
 ```cs
 Entity camera,
 Entity camera,
 ```
 ```
+
 and change
 and change
+
 ```cs
 ```cs
 camera.Update();
 camera.Update();
 var inverseView = Matrix.Invert(camera.ViewMatrix);
 var inverseView = Matrix.Invert(camera.ViewMatrix);
 ```
 ```
+
 to
 to
 `var inverseView = camera.Transform.WorldMatrix;`
 `var inverseView = camera.Transform.WorldMatrix;`
 
 
----
-
 ### FpsCamera.cs
 ### FpsCamera.cs
+
 Remove
 Remove
-```cs
 
 
+```cs
         /// <summary>
         /// <summary>
         /// Gets the camera component used to visualized the scene.
         /// Gets the camera component used to visualized the scene.
         /// </summary>
         /// </summary>
         private Entity Component;
         private Entity Component;
 ```
 ```
 and change
 and change
+
 ```cs
 ```cs
         private void UpdateViewMatrix()
         private void UpdateViewMatrix()
         {
         {
@@ -102,7 +108,8 @@ and change
             Entity.Transform.Rotation = rotation;
             Entity.Transform.Rotation = rotation;
         }
         }
 ```
 ```
-to 
+to
+
 ```cs
 ```cs
 private void UpdateViewMatrix()
 private void UpdateViewMatrix()
 {
 {
@@ -112,4 +119,4 @@ private void UpdateViewMatrix()
 }
 }
 ```
 ```
 
 
-That should be all thats needed to see the smoothing in action as a before and after. You can see the original issue in the Stride Github [here](https://github.com/stride3d/stride/issues/2216) if you need to find more info on the problem.
+That should be all that is needed to see the smoothing in action as a before and after. You can see the original issue in the Stride GitHub [here](https://github.com/stride3d/stride/issues/2216) if you need to find more info on the problem.

+ 3 - 2
en/manual/physics/index.md

@@ -22,6 +22,7 @@ Stride simulates real-world physics such as gravity and collisions. This section
 * [Create a bouncing ball](create-a-bouncing-ball.md): Use the static collider and rigidbody components to create a ball bouncing on a floor
 * [Create a bouncing ball](create-a-bouncing-ball.md): Use the static collider and rigidbody components to create a ball bouncing on a floor
 * [Script a trigger](script-a-trigger.md): Create a trigger that doubles the size of a ball when the ball passes through it
 * [Script a trigger](script-a-trigger.md): Create a trigger that doubles the size of a ball when the ball passes through it
 
 
-## Further reference
+## Additional physics resources
 
 
-Stride uses the open-source [Bullet Physics](http://bulletphysics.org/wordpress/) engine. For detailed information, see the [Bullet User Manual](https://github.com/bulletphysics/bullet3/blob/master/docs/Bullet_User_Manual.pdf).
+- Stride integrates the open-source [Bullet Physics](http://bulletphysics.org/wordpress/) engine. For comprehensive details, consult the [Bullet User Manual](https://github.com/bulletphysics/bullet3/blob/master/docs/Bullet_User_Manual.pdf)
+- For solutions on mitigating physics jitter, refer to our guide on [Fixing Physics Jitter](fix-physics-jitter.md)

+ 2 - 0
en/manual/toc.yml

@@ -448,6 +448,8 @@ items:
             href: physics/create-a-bouncing-ball.md
             href: physics/create-a-bouncing-ball.md
           - name: Script a trigger
           - name: Script a trigger
             href: physics/script-a-trigger.md
             href: physics/script-a-trigger.md
+      - name: Physics jitter
+        href: physics/fix-physics-jitter.md
 
 
   - name: Platforms
   - name: Platforms
     href: platforms/index.md
     href: platforms/index.md