ShaderGraph demo

This commit is contained in:
2026-06-08 14:48:14 +02:00
parent ed8fda0907
commit 4103f5edc7
13 changed files with 19457 additions and 190 deletions

View File

@@ -104,6 +104,9 @@ public class Player : MonoBehaviour
[Tooltip("Animation center of gravity")]
[Range(-1, 1)] public float AnimationCenter;
[Tooltip("Elapsed time since falling")]
[Range(-1, 1)] public float FallingTime;
[Tooltip("Elapsed time since sticked to wall")]
[Range(-1, 1)] public float StickedTime;
@@ -146,6 +149,7 @@ public class Player : MonoBehaviour
private float _groundCheckRadius;
private Collider[] _overlapResults = new Collider[1];
private Vector3 _wallDirection;
private Vector3 _wallNormal;
private Vector3 _wallPosition;
private Vector3 _lastPlatformPosition;
private Quaternion _lastPlatformRotation;
@@ -224,6 +228,11 @@ public class Player : MonoBehaviour
bool isGrounded = rayHit || sphereHit;
// Wall run
if (_settings.WallRun.CanRunOnWalls && !_state.CanStickToWalls)
{
_state.CanStickToWalls = _state.FallingTime > .3f;
}
bool isStickedToWall = false;
if (!isGrounded && _settings.WallRun.CanRunOnWalls && _state.CanStickToWalls && _state.VerticalVelocity < 0)
{
@@ -263,6 +272,7 @@ public class Player : MonoBehaviour
if (_state.IsStickedToWall)
{
_wallDirection = Vector3.ProjectOnPlane(Vector3.Cross(rayInfo.normal, Vector3.up), Vector3.up) * Mathf.Sign(Vector3.Cross(transform.forward, rayInfo.normal).y);
_wallNormal = rayInfo.normal;
_wallPosition = rayInfo.point;
_state.AnimationCenter = raySign;
_state.Running = 1;
@@ -324,6 +334,8 @@ public class Player : MonoBehaviour
// Reset platform velocity
_platformVelocity = Vector3.zero;
_state.FallingTime = 0; ;
}
else
{
@@ -340,6 +352,7 @@ public class Player : MonoBehaviour
_platformVelocity = platformVelocity;
}
_state.FallingTime += deltaTime;
_state.Ground = null;
}
}
@@ -393,8 +406,25 @@ public class Player : MonoBehaviour
}
moveInput *= speed; // Muliply move by speed
_state.Velocity.x = moveInput.x;
_state.Velocity.z = moveInput.z;
float velovityTime = deltaTime * 8;
switch (_state.CurrentState)
{
default:
velovityTime *= 1;
break;
case PlayerState.Jumping:
velovityTime *= .5f;
break;
case PlayerState.Falling:
velovityTime *= .2f;
break;
}
_state.Velocity.x = Mathf.Lerp(_state.Velocity.x, moveInput.x, velovityTime);
_state.Velocity.z = Mathf.Lerp(_state.Velocity.z, moveInput.z, velovityTime);
// Rotate Player
if (moveInput.sqrMagnitude > .001f)
@@ -414,7 +444,11 @@ public class Player : MonoBehaviour
{
if (_jumpAction.triggered && (_state.IsGrounded || _state.IsStickedToWall))
{
_state.Velocity.y = _settings.JumpForce;
if (_state.IsStickedToWall)
_state.Velocity = Vector3.Lerp(_wallNormal, Vector3.up, .4f).normalized * _settings.JumpForce * 1.6f;
else
_state.Velocity.y = _settings.JumpForce;
_state.Ground = null;
_state.IsStickedToWall = false;
_state.CanStickToWalls = false;