Olezen / UnitySourceMovement

Source engine-like movement in Unity, based on Fragsurf by cr4yz (Jake E.).
MIT License
313 stars 46 forks source link

Capsule Collider FIXED! #14

Open DezBoyle opened 3 years ago

DezBoyle commented 3 years ago

I'm too lazy to fork this and fix it BUT I just figured out how to fix the capsule collider movement.

SurfPhysics.cs

public static void GetCapsulePoints (CapsuleCollider capc, Vector3 origin, out Vector3 p1, out Vector3 p2)

{

    var distanceToPoints = capc.height / 2f /*- capc.radius*/;

    p1 = origin + capc.center + Vector3.up * distanceToPoints;

    p2 = origin + capc.center - Vector3.up * distanceToPoints;

}

Removing - capc.radius fixes it.

Hopefully this helps someone.

Fronkln commented 3 years ago

Does this fix movement on stairs?

Dexort-music commented 3 years ago

Hey! Just found that myself, wanted to post here, but been too late) Also, I'm having a bug with jumping. Still Can't figure it out. After first jump collider starts hovering above the ground slightly. With step offset turned on I can climb a step and collider sits normally, but if I then jump and land on that step - same hovering occures. Do you have any ideas, why? _UyDHDGIiS8 J1q6SoRU16w

Dexort-music commented 3 years ago

Also, it seems crouching stops working after this fix. Or maybe I messed something up with my earlier changes.

Dexort-music commented 3 years ago

Fixed crouching. Simplified code. SurfController.cs: this statement is unneccessary: if (_surfer.collider.GetType () == typeof (BoxCollider))

instead after 'else if (crouching)' use:

            // Check if the player can uncrouch
            bool canUncrouch = true;

            Vector3 startPos = _surfer.moveData.origin;
            Vector3 endPos = _surfer.moveData.origin + (uncrouchDown ? Vector3.down : Vector3.up) * heightDifference;

            Trace trace = Tracer.TraceCollider(_surfer.collider, startPos, endPos, SurfPhysics.groundLayerMask);

            if (trace.hitCollider != null)
                canUncrouch = false;