Using AnimationCurve instead of cubic ease out for jump
This commit is contained in:
parent
74eb85dad5
commit
b275bcc1db
@ -9,12 +9,12 @@ GameObject:
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1214567908930553594}
|
||||
- component: {fileID: 1214567908930553595}
|
||||
- component: {fileID: 1214567908930553592}
|
||||
- component: {fileID: 3126145803593047825}
|
||||
- component: {fileID: 1214567908930553595}
|
||||
- component: {fileID: 1214567908930553477}
|
||||
- component: {fileID: 945832017}
|
||||
- component: {fileID: 945832018}
|
||||
- component: {fileID: 3126145803593047825}
|
||||
m_Layer: 0
|
||||
m_Name: Vampire
|
||||
m_TagString: Untagged
|
||||
@ -36,6 +36,40 @@ Transform:
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1214567908930553592
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1214567908930553593}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 639be549366b46748bd86eb6cea796a3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
|
||||
--- !u!114 &3126145803593047825
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1214567908930553593}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3d475633c5bc498fac5a9e5ead64da55, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
<Health>k__BackingField: 10
|
||||
movementSpeed: 0
|
||||
rotSpeed: 0
|
||||
fov: 0
|
||||
attackRange: 0
|
||||
attackDmg: 0
|
||||
attackCooldown: 0
|
||||
target: {fileID: 0}
|
||||
healthBar: {fileID: 0}
|
||||
--- !u!212 &1214567908930553595
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -87,19 +121,6 @@ SpriteRenderer:
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
--- !u!114 &1214567908930553592
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1214567908930553593}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 639be549366b46748bd86eb6cea796a3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
|
||||
--- !u!114 &1214567908930553477
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -247,24 +268,3 @@ CircleCollider2D:
|
||||
m_Offset: {x: 0, y: 0}
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.5
|
||||
--- !u!114 &3126145803593047825
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1214567908930553593}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3d475633c5bc498fac5a9e5ead64da55, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
<Health>k__BackingField: 10
|
||||
movementSpeed: 0
|
||||
rotSpeed: 0
|
||||
fov: 0
|
||||
attackRange: 0
|
||||
attackDmg: 0
|
||||
attackCooldown: 0
|
||||
target: {fileID: 0}
|
||||
healthBar: {fileID: 0}
|
||||
|
||||
@ -4,7 +4,7 @@ using UnityEngine.InputSystem;
|
||||
|
||||
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
|
||||
public class PlayerMovement : MonoBehaviour {
|
||||
[SerializeField] PlayerStats playerStats = null!;
|
||||
[SerializeField] PlayerStats stats = null!;
|
||||
Rigidbody2D rb = null!;
|
||||
|
||||
Vector2 moveDirection;
|
||||
@ -41,7 +41,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
return;
|
||||
|
||||
if (safeZone.IsInSafeZone) {
|
||||
if (moveDirection.magnitude >= safeZone.stats.minJumpJoystickValue)
|
||||
if (moveDirection.magnitude >= safeZone.stats.MinJumpJoystickValue)
|
||||
SwitchState(new ExitSafeZoneMovementState(safeZone, moveDirection));
|
||||
} else //TODO if (AngleBetween(moveDirection, toSafeZone) < 90)
|
||||
SwitchState(new EnterSafeZoneMovementState(safeZone));
|
||||
@ -83,7 +83,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
|
||||
class NormalMovementState : BaseState {
|
||||
public override BaseState? FixedUpdateState(PlayerMovement playerMovement) {
|
||||
playerMovement.rb.velocity = (Vector3)playerMovement.moveDirection * playerMovement.playerStats.movementSpeed;
|
||||
playerMovement.rb.velocity = (Vector3)playerMovement.moveDirection * playerMovement.stats.movementSpeed;
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -116,20 +116,19 @@ public class PlayerMovement : MonoBehaviour {
|
||||
playerMovement.rb.MovePosition(Vector3.Lerp(
|
||||
startPosition,
|
||||
target,
|
||||
CubicEaseOut(currentTime / duration)
|
||||
ModifyLerpTime(currentTime / duration)
|
||||
));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected virtual BaseState Transition() => new NormalMovementState();
|
||||
|
||||
static float CubicEaseOut(float t) => 1 - Mathf.Pow(1 - t, 3);
|
||||
protected virtual float ModifyLerpTime(float t) => t;
|
||||
}
|
||||
|
||||
class EnterSafeZoneMovementState : JumpingMovementState {
|
||||
readonly SafeZone safeZone;
|
||||
public EnterSafeZoneMovementState(SafeZone safeZone) : base(safeZone.stats.jumpDuration, safeZone.transform.position) {
|
||||
public EnterSafeZoneMovementState(SafeZone safeZone) : base(safeZone.stats.JumpDuration, safeZone.transform.position) {
|
||||
this.safeZone = safeZone;
|
||||
}
|
||||
|
||||
@ -141,11 +140,13 @@ public class PlayerMovement : MonoBehaviour {
|
||||
}
|
||||
|
||||
protected override BaseState Transition() => new ImmobileMovementState();
|
||||
|
||||
protected override float ModifyLerpTime(float t) => safeZone.stats.JumpSpeedCurve.Evaluate(t);
|
||||
}
|
||||
|
||||
class ExitSafeZoneMovementState : JumpingMovementState {
|
||||
readonly SafeZone safeZone;
|
||||
public ExitSafeZoneMovementState(SafeZone safeZone, Vector2 direction) : base(safeZone.stats.jumpDuration, safeZone.GetOutsidePosition(direction)) {
|
||||
public ExitSafeZoneMovementState(SafeZone safeZone, Vector2 direction) : base(safeZone.stats.JumpDuration, safeZone.GetOutsidePosition(direction)) {
|
||||
this.safeZone = safeZone;
|
||||
}
|
||||
|
||||
@ -155,6 +156,8 @@ public class PlayerMovement : MonoBehaviour {
|
||||
safeZone.ExitSafeZone();
|
||||
playerMovement.rb.velocity = Vector2.zero;
|
||||
}
|
||||
|
||||
protected override float ModifyLerpTime(float t) => safeZone.stats.JumpSpeedCurve.Evaluate(t);
|
||||
}
|
||||
|
||||
class ImmobileMovementState : BaseState {
|
||||
@ -164,7 +167,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
return;
|
||||
|
||||
Vector3 dropPosition = playerMovement.safeZone.GetOutsidePosition(playerMovement.moveDirection);
|
||||
bool canJump = playerMovement.moveDirection.magnitude >= playerMovement.safeZone.stats.minJumpJoystickValue;
|
||||
bool canJump = playerMovement.moveDirection.magnitude >= playerMovement.safeZone.stats.MinJumpJoystickValue;
|
||||
Gizmos.color = canJump ? Color.green : Color.red;
|
||||
Gizmos.DrawLine(playerMovement.transform.position, dropPosition);
|
||||
if (canJump)
|
||||
|
||||
@ -21,6 +21,6 @@ public class SafeZone : MonoBehaviour {
|
||||
}
|
||||
|
||||
public Vector3 GetOutsidePosition(Vector2 direction) {
|
||||
return transform.position + (moatCollider.radius + stats.jumpOffset) * (Vector3)direction;
|
||||
return transform.position + (moatCollider.radius + stats.JumpOffset) * (Vector3)direction;
|
||||
}
|
||||
}
|
||||
@ -2,10 +2,15 @@
|
||||
|
||||
[CreateAssetMenu]
|
||||
public class SafeZoneStats : ScriptableObject {
|
||||
[SerializeField] [Min(0f)]
|
||||
public float jumpDuration = 1.2f;
|
||||
[SerializeField] [Range(0f, 1f)]
|
||||
public float minJumpJoystickValue = 0.5f;
|
||||
[SerializeField] [Min(0f)]
|
||||
public float jumpOffset = 1f;
|
||||
[field: SerializeField] [field: Min(0f)]
|
||||
public float JumpDuration { get; private set; } = 1.2f;
|
||||
|
||||
[field: SerializeField] [field: Range(0f, 1f)]
|
||||
public float MinJumpJoystickValue { get; private set; } = 0.5f;
|
||||
|
||||
[field: SerializeField] [field: Min(0f)]
|
||||
public float JumpOffset { get; private set; } = 1f;
|
||||
|
||||
[field: SerializeField]
|
||||
public AnimationCurve JumpSpeedCurve { get; private set; }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user