Fixed throwing on ground

This commit is contained in:
Jason Durand 01 2022-04-02 17:42:24 -04:00
parent c07aa285c8
commit d57eab3e92
10 changed files with 22 additions and 37 deletions

View File

@ -193,6 +193,8 @@ MonoBehaviour:
target: {fileID: 0}
halo: {fileID: 160873202674104038}
AIStats: {fileID: 11400000, guid: 9d8a9a664d932d0498d5eca7607eeb53, type: 2}
thrownFromSafeZone: 0
thrownTargetPosition: {x: 0, y: 0, z: 0}
--- !u!50 &1427479462206541758
Rigidbody2D:
serializedVersion: 4
@ -206,7 +208,7 @@ Rigidbody2D:
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_LinearDrag: 1
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 6200000, guid: 72c8b57001d325c418a78771641a077f, type: 2}

View File

@ -630,10 +630,6 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1214567908930553595, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
propertyPath: m_SortingOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1967503440015794769, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
propertyPath: gameFlowManager
value:

View File

@ -51,3 +51,5 @@ MonoBehaviour:
m_PostInfinity: 2
m_RotationOrder: 4
<ThrownDurationPerMeter>k__BackingField: 0.15
<MinVelocityWhenThrown>k__BackingField: 2
throwForce: 5

View File

@ -16,4 +16,10 @@ public class AIStats : ScriptableObject {
[field: SerializeField]
public float ThrownDurationPerMeter { get; private set; }
[field: SerializeField] [field: Min(0f)]
public float MinVelocityWhenThrown { get; private set; } = 5f;
[field: SerializeField] [field: Min(0f)]
public float throwForce = 3f;
}

View File

@ -9,9 +9,6 @@ public class Entity : MonoBehaviour {
[Required]
public GameFlowManager gameFlowManager = null!;
[field: SerializeField]
[field: Required]
public EntityStats stats { get; private set; }
[field: SerializeField] public float Health { get; private set; }
[Min(10f)]
protected float initialHealth;
@ -48,13 +45,7 @@ public class Entity : MonoBehaviour {
protected virtual void Update() { }
protected virtual void FixedUpdate() {
//TODO sqrMagnitude?
if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenThrown) {
rb.velocity = Vector2.zero;
beingPushed = false;
}
}
protected virtual void FixedUpdate() {}
protected virtual void Attack() {

View File

@ -1,6 +0,0 @@
using UnityEngine;
public class EntityStats {
[field: SerializeField] [field: Min(0f)]
public float MinVelocityWhenThrown { get; private set; } = 5f;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: f3b49b8d7dbc43dfbd074996aa811570
timeCreated: 1648908811

View File

@ -76,7 +76,7 @@ public class MinionThrower : MonoBehaviour {
var newMinion = Instantiate(minionBar.GetCurrentMinion().gameObject, transform.position + new Vector3(throwDirection.x, throwDirection.y, 0f) * 1f, Quaternion.identity)
.GetComponent<Monster>();
if (movement.GetSafeZone() is {} safeZone) {
if (movement.GetSafeZoneIfImmobile() is {} safeZone) {
newMinion.thrownFromSafeZone = true;
newMinion.thrownTargetPosition = safeZone.GetOutsidePosition(throwDirection);
}

View File

@ -2,8 +2,8 @@
using UnityEngine;
public class Monster : AIEntity {
public bool thrownFromSafeZone;
public Vector3 thrownTargetPosition;
[HideInInspector] public bool thrownFromSafeZone;
[HideInInspector] public Vector3 thrownTargetPosition;
// Start is called before the first frame update
override protected void Start()
@ -65,17 +65,14 @@ public class Monster : AIEntity {
public override void EnterState() {
base.EnterState();
entity.rb.SetEnabled(false);
entity.rb.velocity = entity.direction * entity.AIStats.throwForce;
}
public override void LeaveState() {
base.LeaveState();
entity.rb.SetEnabled(true);
}
public override BaseState? FixedUpdateState()
=> entity.rb.velocity.magnitude < entity.stats.MinVelocityWhenThrown
public override BaseState? FixedUpdateState() {
Debug.Log($"Velocity: {entity.rb.velocity.magnitude}");
return entity.rb.velocity.magnitude < entity.AIStats.MinVelocityWhenThrown
? new FindTargetState(entity)
: null;
}
}
}

View File

@ -49,8 +49,8 @@ public class PlayerMovement : MonoBehaviour {
#endregion
public SafeZone? GetSafeZone() {
return safeZone;
public SafeZone? GetSafeZoneIfImmobile() {
return currentState is ImmobileMovementState ? safeZone : null;
}
#region Inputs