mirror of
https://github.com/celisej567/UnitySourceMovement.git
synced 2025-12-31 09:48:17 +03:00
Add files via upload
This commit is contained in:
@@ -74,9 +74,10 @@ namespace Fragsurf.Movement {
|
||||
speed = _surfer.moveData.velocity.magnitude;
|
||||
_surfer.moveData.velocity.y = yVel;
|
||||
|
||||
float maxDistPerFrame = 1f;
|
||||
float maxDistPerFrame = 0.05f;
|
||||
Vector3 velocityThisFrame = _surfer.moveData.velocity * _deltaTime;
|
||||
float velocityDistLeft = velocityThisFrame.magnitude;
|
||||
float velocityDist = velocityThisFrame.magnitude;
|
||||
float velocityDistLeft = velocityDist;
|
||||
float initialVel = velocityDistLeft;
|
||||
while (velocityDistLeft > 0f) {
|
||||
|
||||
@@ -88,7 +89,7 @@ namespace Fragsurf.Movement {
|
||||
_surfer.moveData.origin += velThisLoop;
|
||||
|
||||
// don't penetrate walls
|
||||
SurfPhysics.ResolveCollisions (_surfer.collider, ref _surfer.moveData.origin, ref _surfer.moveData.velocity, _surfer.moveData.rigidbodyPushForce);
|
||||
SurfPhysics.ResolveCollisions (_surfer.collider, ref _surfer.moveData.origin, ref _surfer.moveData.velocity, _surfer.moveData.rigidbodyPushForce, amountThisLoop / velocityDist);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,12 @@ namespace Fragsurf.Movement {
|
||||
/// <param name="origin"></param>
|
||||
/// <param name="velocity"></param>
|
||||
/// http://www.00jknight.com/blog/unity-character-controller
|
||||
|
||||
public static void ResolveCollisions (Collider collider, ref Vector3 origin, ref Vector3 velocity, float rigidbodyPushForce) {
|
||||
ResolveCollisions (collider, ref origin, ref velocity, rigidbodyPushForce, 1f);
|
||||
}
|
||||
|
||||
public static void ResolveCollisions (Collider collider, ref Vector3 origin, ref Vector3 velocity, float rigidbodyPushForce, float velocityMultiplier) {
|
||||
|
||||
// manual collision resolving
|
||||
int numOverlaps = 0;
|
||||
@@ -59,17 +64,18 @@ namespace Fragsurf.Movement {
|
||||
Quaternion.identity, _colliders [i], _colliders [i].transform.position,
|
||||
_colliders [i].transform.rotation, out direction, out distance)) {
|
||||
|
||||
// Handle collision
|
||||
direction.Normalize ();
|
||||
Vector3 penetrationVector = direction * distance;
|
||||
Vector3 velocityProjected = Vector3.Project (velocity, -direction);
|
||||
velocityProjected.y = 0; // don't touch y velocity, we need it to calculate fall damage elsewhere
|
||||
origin += penetrationVector;
|
||||
velocity -= velocityProjected;
|
||||
velocity -= velocityProjected * velocityMultiplier;
|
||||
|
||||
Rigidbody rb = _colliders [i].GetComponentInParent<Rigidbody> ();
|
||||
if (rb)
|
||||
if (!rb.isKinematic)
|
||||
rb.AddForceAtPosition (velocityProjected * rigidbodyPushForce, origin, ForceMode.Impulse);
|
||||
rb.AddForceAtPosition (velocityProjected * velocityMultiplier * rigidbodyPushForce, origin, ForceMode.Impulse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user