Added threat speed up
This commit is contained in:
parent
817edd2938
commit
fadffbc004
@ -2105,6 +2105,11 @@ PrefabInstance:
|
|||||||
insertIndex: -1
|
insertIndex: -1
|
||||||
addedObject: {fileID: 1319432447}
|
addedObject: {fileID: 1319432447}
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: f82ba3fc97fa2e941990becbb5eca05b, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: f82ba3fc97fa2e941990becbb5eca05b, type: 3}
|
||||||
|
--- !u!4 &1319432443 stripped
|
||||||
|
Transform:
|
||||||
|
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: f82ba3fc97fa2e941990becbb5eca05b, type: 3}
|
||||||
|
m_PrefabInstance: {fileID: 1319432442}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
--- !u!1 &1319432444 stripped
|
--- !u!1 &1319432444 stripped
|
||||||
GameObject:
|
GameObject:
|
||||||
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: f82ba3fc97fa2e941990becbb5eca05b, type: 3}
|
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: f82ba3fc97fa2e941990becbb5eca05b, type: 3}
|
||||||
@ -2147,6 +2152,7 @@ MonoBehaviour:
|
|||||||
rb: {fileID: 1319432448}
|
rb: {fileID: 1319432448}
|
||||||
moveSpeed: 1
|
moveSpeed: 1
|
||||||
stopDistance: 1
|
stopDistance: 1
|
||||||
|
usePlayerSpeed: 0
|
||||||
--- !u!65 &1319432447
|
--- !u!65 &1319432447
|
||||||
BoxCollider:
|
BoxCollider:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -2525,6 +2531,11 @@ MonoBehaviour:
|
|||||||
fallingStateName: Falling
|
fallingStateName: Falling
|
||||||
secondHitWindow: 10
|
secondHitWindow: 10
|
||||||
stateWaitTimeout: 3
|
stateWaitTimeout: 3
|
||||||
|
speedUpFromBomb: 1
|
||||||
|
bombEnemy: {fileID: 0}
|
||||||
|
boostDistance: 12
|
||||||
|
maxSpeedBoost: 4
|
||||||
|
boostLerp: 5
|
||||||
waitingForGameOver: 0
|
waitingForGameOver: 0
|
||||||
validateStatesOnStart: 1
|
validateStatesOnStart: 1
|
||||||
runTag: Run
|
runTag: Run
|
||||||
@ -8855,6 +8866,14 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 6341515697253773609, guid: 515cc30092d66fe4dba290f9d6415a60, type: 3}
|
||||||
|
propertyPath: bombEnemy
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1319432443}
|
||||||
|
- target: {fileID: 6341515697253773609, guid: 515cc30092d66fe4dba290f9d6415a60, type: 3}
|
||||||
|
propertyPath: maxSpeedBoost
|
||||||
|
value: 2.5
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6341515697253773609, guid: 515cc30092d66fe4dba290f9d6415a60, type: 3}
|
- target: {fileID: 6341515697253773609, guid: 515cc30092d66fe4dba290f9d6415a60, type: 3}
|
||||||
propertyPath: initialJumpVelocity
|
propertyPath: initialJumpVelocity
|
||||||
value: 4
|
value: 4
|
||||||
|
@ -55,6 +55,16 @@ public class ChasePlayerController : MonoBehaviour
|
|||||||
[SerializeField] private float secondHitWindow = 10f;
|
[SerializeField] private float secondHitWindow = 10f;
|
||||||
[SerializeField] private float stateWaitTimeout = 3f;
|
[SerializeField] private float stateWaitTimeout = 3f;
|
||||||
|
|
||||||
|
[Header("Threat-Based Speedup")]
|
||||||
|
[SerializeField] private bool speedUpFromBomb = true;
|
||||||
|
[SerializeField] private Transform bombEnemy; // assign in Inspector or auto-find by tag "BombEnemy"
|
||||||
|
[SerializeField] private float boostDistance = 12f; // within this range -> up to max boost
|
||||||
|
[SerializeField] private float maxSpeedBoost = 4f; // extra speed added at zero distance
|
||||||
|
[SerializeField] private float boostLerp = 5f; // smoothing (higher = snappier)
|
||||||
|
|
||||||
|
private float baseMoveSpeed; // remembers your normal run speed
|
||||||
|
|
||||||
|
|
||||||
public static System.Action<float> OnMoveSpeedChanged;
|
public static System.Action<float> OnMoveSpeedChanged;
|
||||||
|
|
||||||
// ----- runtime state -----
|
// ----- runtime state -----
|
||||||
@ -110,7 +120,12 @@ public class ChasePlayerController : MonoBehaviour
|
|||||||
runShortHash = Animator.StringToHash(runStateName);
|
runShortHash = Animator.StringToHash(runStateName);
|
||||||
fallShortHash = Animator.StringToHash(fallStateName);
|
fallShortHash = Animator.StringToHash(fallStateName);
|
||||||
fallingShortHash = Animator.StringToHash(fallingStateName);
|
fallingShortHash = Animator.StringToHash(fallingStateName);
|
||||||
|
if (bombEnemy == null)
|
||||||
|
{
|
||||||
|
var bomb = GameObject.FindGameObjectWithTag("BombEnemy");
|
||||||
|
if (bomb) bombEnemy = bomb.transform;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate states (optional)
|
// Validate states (optional)
|
||||||
if (validateStatesOnStart)
|
if (validateStatesOnStart)
|
||||||
{
|
{
|
||||||
@ -150,8 +165,24 @@ public class ChasePlayerController : MonoBehaviour
|
|||||||
|
|
||||||
ApplyBetterJumpGravity();
|
ApplyBetterJumpGravity();
|
||||||
ClampVerticalSpeed();
|
ClampVerticalSpeed();
|
||||||
|
ApplyThreatSpeedup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyThreatSpeedup()
|
||||||
|
{
|
||||||
|
if (!speedUpFromBomb || bombEnemy == null || waitingForGameOver) return;
|
||||||
|
|
||||||
|
float dist = Vector3.Distance(transform.position, bombEnemy.position);
|
||||||
|
// 0 when far, 1 when enemy is on top of us
|
||||||
|
float t = Mathf.Clamp01((boostDistance - dist) / boostDistance);
|
||||||
|
|
||||||
|
float target = baseMoveSpeed + maxSpeedBoost * t;
|
||||||
|
// Smoothly approach the target; no event fire here so enemy doesn't copy this boost
|
||||||
|
moveSpeed = Mathf.Lerp(moveSpeed, target, Time.deltaTime * boostLerp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
MoveForwardAndSide();
|
MoveForwardAndSide();
|
||||||
|
@ -10,6 +10,8 @@ public class ChaseRunEnemy : MonoBehaviour
|
|||||||
private Transform player;
|
private Transform player;
|
||||||
private float stopDistanceSqr;
|
private float stopDistanceSqr;
|
||||||
private bool isStopped = false;
|
private bool isStopped = false;
|
||||||
|
[Header("Speed Source")]
|
||||||
|
public bool usePlayerSpeed = false; // set to false so enemy won't copy the wolf's boost
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@ -30,12 +32,14 @@ public class ChaseRunEnemy : MonoBehaviour
|
|||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
ChasePlayerController.OnMoveSpeedChanged += UpdateMoveSpeed;
|
if (usePlayerSpeed)
|
||||||
|
ChasePlayerController.OnMoveSpeedChanged += UpdateMoveSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisable()
|
private void OnDisable()
|
||||||
{
|
{
|
||||||
ChasePlayerController.OnMoveSpeedChanged -= UpdateMoveSpeed;
|
if (usePlayerSpeed)
|
||||||
|
ChasePlayerController.OnMoveSpeedChanged += UpdateMoveSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateMoveSpeed(float speed)
|
private void UpdateMoveSpeed(float speed)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user