From bdf47cf0fd36a5c858575a805cca70ab623868eb Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 29 Oct 2020 19:39:42 +0800 Subject: *misc --- Assets/Scripts/Physics/PhysicsWorld.cs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'Assets/Scripts/Physics/PhysicsWorld.cs') diff --git a/Assets/Scripts/Physics/PhysicsWorld.cs b/Assets/Scripts/Physics/PhysicsWorld.cs index cc7ce7c6..41ea59f8 100644 --- a/Assets/Scripts/Physics/PhysicsWorld.cs +++ b/Assets/Scripts/Physics/PhysicsWorld.cs @@ -28,6 +28,9 @@ public enum PhysicsTag Oponent = 1 << 1, // 从属于对手 } +/// +/// 物理子系统 +/// public class PhysicsWorld : Singleton { private int m_UpdateRate = 60; @@ -221,15 +224,24 @@ public class PhysicsWorld : Singleton body.transform.position = position; - PhysicsBox box = prim as PhysicsBox; - if(box.Bottom < 0.1f) + if(prim.IsOnGround) { + // pos=0, Vy=0 position.y = 0.1f; body.transform.position = position; - velocity.y = 0; - body.Velocity = velocity; - } - } + + // 地面摩擦力 + if(body.Velocity.x != 0 && body.GroundFriction != 0) + { + float dv = body.GroundFriction * dt; + dv = Mathf.Min(dv, Mathf.Abs(body.Velocity.x)); + dv = body.Velocity.x > 0 ? -dv : dv; + velocity.x += dv; + } + velocity.y = 0; + body.Velocity = velocity; + } + } void SolveCollision(PhysicsPrimitive prim, PhysicsCollisionInfo collision, float dt) { -- cgit v1.1-26-g67d0