Started adding AIEntity's ThrownState
This commit is contained in:
parent
25a10047ad
commit
a7a29f4cce
@ -16,6 +16,67 @@ public class AIEntity : Entity
|
||||
}
|
||||
}
|
||||
|
||||
/*//Basically a copy of JumpingMovementState
|
||||
class NonPhysicThrownState : BaseStateAI {
|
||||
readonly Vector3 target;
|
||||
|
||||
Vector3 startPosition;
|
||||
float duration;
|
||||
float startTime;
|
||||
|
||||
public NonPhysicThrownState(AIEntity entity, Vector3 target) : base(entity) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public override void EnterState() {
|
||||
base.EnterState();
|
||||
|
||||
duration = entity.AIStats.ThrownDurationPerMeter * Vector3.Distance(entity.transform.position, target);
|
||||
startPosition = entity.transform.position;
|
||||
startTime = Time.time;
|
||||
entity.rb.SetEnabled(false);
|
||||
}
|
||||
|
||||
public override void LeaveState() {
|
||||
base.LeaveState();
|
||||
entity.rb.SetEnabled(true);
|
||||
}
|
||||
|
||||
public override BaseState? FixedUpdateState() {
|
||||
float currentTime = Time.time - startTime;
|
||||
if (currentTime >= duration)
|
||||
return new FindTargetState(entity);
|
||||
|
||||
entity.rb.MovePosition(Vector3.Lerp(
|
||||
startPosition,
|
||||
target,
|
||||
entity.AIStats.ThrownCurve.Evaluate(currentTime / duration)
|
||||
));
|
||||
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
class ThrownState : BaseStateAI {
|
||||
public ThrownState(AIEntity entity) : base(entity) {}
|
||||
|
||||
public override void EnterState() {
|
||||
base.EnterState();
|
||||
|
||||
entity.rb.SetEnabled(false);
|
||||
}
|
||||
|
||||
public override void LeaveState() {
|
||||
base.LeaveState();
|
||||
entity.rb.SetEnabled(true);
|
||||
}
|
||||
|
||||
public override BaseState? FixedUpdateState()
|
||||
=> entity.rb.velocity.magnitude < entity.stats.MinVelocityWhenThrown
|
||||
? new FindTargetState(entity)
|
||||
: null;
|
||||
}
|
||||
|
||||
class SeekState : BaseStateAI{
|
||||
public SeekState(AIEntity entity) : base(entity){
|
||||
|
||||
|
||||
@ -3,4 +3,10 @@ using UnityEngine;
|
||||
[CreateAssetMenu]
|
||||
public class AIStats : ScriptableObject {
|
||||
public float closeEnough = 1f;
|
||||
|
||||
[field: SerializeField]
|
||||
public AnimationCurve ThrownCurve { get; }
|
||||
|
||||
[field: SerializeField]
|
||||
public float ThrownDurationPerMeter { get; }
|
||||
}
|
||||
@ -39,7 +39,7 @@ public class Entity : MonoBehaviour
|
||||
|
||||
protected virtual void FixedUpdate() {
|
||||
//TODO sqrMagnitude?
|
||||
if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenPushed) {
|
||||
if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenThrown) {
|
||||
rb.velocity = Vector2.zero;
|
||||
beingPushed = false;
|
||||
}
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
|
||||
public class EntityStats {
|
||||
[field: SerializeField] [field: Min(0f)]
|
||||
public float MinVelocityWhenPushed { get; private set; } = 5f;
|
||||
public float MinVelocityWhenThrown { get; private set; } = 5f;
|
||||
}
|
||||
@ -91,12 +91,6 @@ public class PlayerMovement : MonoBehaviour {
|
||||
safeZone = null;
|
||||
}
|
||||
|
||||
void SetRigidbodyEnabled(bool enabled) {
|
||||
rb.velocity = Vector2.zero;
|
||||
rb.angularVelocity = 0f;
|
||||
rb.isKinematic = !enabled;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region States
|
||||
@ -171,7 +165,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
base.EnterState();
|
||||
|
||||
safeZone.EnterSafeZone();
|
||||
playerMovement.SetRigidbodyEnabled(false);
|
||||
playerMovement.rb.SetEnabled(false);
|
||||
}
|
||||
|
||||
protected override BaseState Transition() => new ImmobileMovementState(playerMovement);
|
||||
@ -190,7 +184,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
base.EnterState();
|
||||
|
||||
safeZone.ExitSafeZone();
|
||||
playerMovement.SetRigidbodyEnabled(true);
|
||||
playerMovement.rb.SetEnabled(true);
|
||||
}
|
||||
|
||||
protected override float ModifyLerpTime(float t) => safeZone.Stats.JumpSpeedCurve.Evaluate(t);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public static class Utils {
|
||||
public static bool WasPressedThisFrame(this InputAction.CallbackContext ctx, ref bool lastValue) {
|
||||
@ -8,4 +9,10 @@ public static class Utils {
|
||||
|
||||
return wasJustPressed;
|
||||
}
|
||||
|
||||
public static void SetEnabled(this Rigidbody2D rb, bool enabled) {
|
||||
rb.velocity = Vector2.zero;
|
||||
rb.angularVelocity = 0f;
|
||||
rb.isKinematic = !enabled;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user