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;

View File

@@ -5,7 +5,6 @@ public class RocketExplosion : MonoBehaviour
[System.Serializable]
public class References
{
public SphereCollider Collider;
public ParticleSystem Explosion;
}
@@ -13,15 +12,36 @@ public class RocketExplosion : MonoBehaviour
public class Settings
{
public float Radius = 5;
public float Strength = 1000;
}
[SerializeField] private References _references;
[SerializeField] private Settings _settings;
private float radius;
private float time;
//private float radius;
//private float time;
void Awake()
void Start()
{
Vector3 originPos = transform.position;
Collider[] colliders = Physics.OverlapSphere(originPos, _settings.Radius);
foreach (Collider hit in colliders)
{
Rigidbody rb = hit.GetComponent<Rigidbody>();
if (rb != null)
{
float strength = _settings.Strength;
strength *= 1 - Vector3.Distance(originPos, hit.transform.position) / _settings.Radius;
rb.AddExplosionForce(strength, originPos, _settings.Radius);
}
}
}
/*void Awake()
{
radius = 1;
_references.Explosion.Play();
@@ -36,5 +56,5 @@ public class RocketExplosion : MonoBehaviour
time += Time.deltaTime;
if (time > 5)
Destroy(gameObject);
}
}*/
}