From 8583c51cfc420b9f3ab6d034d3495cd0f78666b3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 4 Mar 2017 22:41:31 +1100 Subject: [PATCH] More configurable physics --- .../Entities/Components/PhysicsComponent.cs | 14 ++++++-------- ClassicalSharp/Entities/Model/IModel.cs | 11 +++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ClassicalSharp/Entities/Components/PhysicsComponent.cs b/ClassicalSharp/Entities/Components/PhysicsComponent.cs index f3bb873f5..5878ca56d 100644 --- a/ClassicalSharp/Entities/Components/PhysicsComponent.cs +++ b/ClassicalSharp/Entities/Components/PhysicsComponent.cs @@ -104,10 +104,8 @@ namespace ClassicalSharp.Entities { static Vector3 waterDrag = new Vector3(0.8f, 0.8f, 0.8f), lavaDrag = new Vector3(0.5f, 0.5f, 0.5f), - ropeDrag = new Vector3(0.5f, 0.85f, 0.5f), - normalDrag = new Vector3(0.91f, 0.98f, 0.91f), - airDrag = new Vector3(0.6f, 1f, 0.6f); - const float liquidGrav = 0.02f, ropeGrav = 0.034f, normalGrav = 0.08f; + ropeDrag = new Vector3(0.5f, 0.85f, 0.5f); + const float liquidGrav = 0.02f, ropeGrav = 0.034f; public void PhysicsTick(Vector3 vel) { if (hacks.Noclip) entity.onGround = false; @@ -130,12 +128,12 @@ namespace ClassicalSharp.Entities { MoveNormal(vel, 0.02f * 1.7f, ropeDrag, ropeGrav, yMul); } else { float factor = !(hacks.Flying || hacks.Noclip) && entity.onGround ? 0.1f : 0.02f; - float gravity = useLiquidGravity ? liquidGrav : normalGrav; + float gravity = useLiquidGravity ? liquidGrav : entity.Model.Gravity; if (hacks.Flying || hacks.Noclip) { - MoveFlying(vel, factor * horMul, normalDrag, gravity, yMul); + MoveFlying(vel, factor * horMul, entity.Model.Drag, gravity, yMul); } else { - MoveNormal(vel, factor * horMul, normalDrag, gravity, yMul); + MoveNormal(vel, factor * horMul, entity.Model.Drag, gravity, yMul); } if (entity.BlockUnderFeet == Block.Ice && !(hacks.Flying || hacks.Noclip)) { @@ -147,7 +145,7 @@ namespace ClassicalSharp.Entities { entity.Velocity.Z *= scale; } } else if (entity.onGround || hacks.Flying) { - entity.Velocity = Utils.Mul(entity.Velocity, airDrag); // air drag or ground friction + entity.Velocity = Utils.Mul(entity.Velocity, entity.Model.GroundFriction); // air drag or ground friction } } diff --git a/ClassicalSharp/Entities/Model/IModel.cs b/ClassicalSharp/Entities/Model/IModel.cs index 063fcc7c9..7a54ed41e 100644 --- a/ClassicalSharp/Entities/Model/IModel.cs +++ b/ClassicalSharp/Entities/Model/IModel.cs @@ -30,6 +30,16 @@ namespace ClassicalSharp.Model { /// Whether this entity requires downloading of a skin texture. public bool UsesSkin = true; + /// Gravity applied to this entity. + public virtual float Gravity { get { return 0.08f; } } + + /// Drag applied to the entity. + public virtual Vector3 Drag { get { return new Vector3(0.91f, 0.98f, 0.91f); } } + + /// Friction applied to the entity when is on the ground. + public virtual Vector3 GroundFriction { get { return new Vector3(0.6f, 1.0f, 0.6f); } } + + /// Vertical offset from the model's feet/base that the name texture should be drawn at. public abstract float NameYOffset { get; } @@ -45,6 +55,7 @@ namespace ClassicalSharp.Model { /// Scaling factor applied, multiplied by the entity's current model scale. public virtual float NameScale { get { return 1; } } + /// The size of the bounding box that is used when /// performing collision detection for this model. public abstract Vector3 CollisionSize { get; }