diff options
author | chai <chaifix@163.com> | 2020-10-29 19:39:42 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-29 19:39:42 +0800 |
commit | bdf47cf0fd36a5c858575a805cca70ab623868eb (patch) | |
tree | c93691007f656380decbcb93690292e273d4e217 /Assets/Scripts/Physics/PhysicsWorld.cs | |
parent | 61fbc2cdd8368505c3c8ce893af020463cc2a669 (diff) |
*misc
Diffstat (limited to 'Assets/Scripts/Physics/PhysicsWorld.cs')
-rw-r--r-- | Assets/Scripts/Physics/PhysicsWorld.cs | 24 |
1 files changed, 18 insertions, 6 deletions
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, // 从属于对手
}
+/// <summary>
+/// 物理子系统
+/// </summary>
public class PhysicsWorld : Singleton<PhysicsWorld>
{
private int m_UpdateRate = 60;
@@ -221,15 +224,24 @@ public class PhysicsWorld : Singleton<PhysicsWorld> 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)
{
|