Pull request #1: Jason

Merge in CEGJ/ludumdare50 from jason to dev

* commit '4e91117d4bfe1d5b811a65b5fd008b715891f55a':
  Forgot to remove BaseState
  Pretty ok transition in out of safe zone
  Moved input action setup to PlayerInput component
  Quick normal to jumping transition + Camera
  Apply changes to Vampire prefab
  Actually use rigidbody2d
  Added quick joystick to move + scriptableobject
This commit is contained in:
Jason Durand 01 2022-04-02 07:45:52 +00:00
commit 907a828d84
17 changed files with 2440 additions and 18 deletions

1741
Assets/Prefabs/Arena.prefab Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 581322f036f3ff1448d4d2ec70f295a4
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -12,6 +12,8 @@ GameObject:
- component: {fileID: 1214567908930553595}
- component: {fileID: 1214567908930553592}
- component: {fileID: 1214567908930553477}
- component: {fileID: 945832017}
- component: {fileID: 945832018}
m_Layer: 0
m_Name: Vampire
m_TagString: Untagged
@ -96,6 +98,7 @@ MonoBehaviour:
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
@ -122,11 +125,35 @@ MonoBehaviour:
m_Calls: []
m_ActionEvents:
- m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 1214567908930553592}
m_TargetAssemblyTypeName: PlayerMovement, Assembly-CSharp
m_MethodName: OnMove
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_ActionId: 1071c237-0382-46b6-9750-c39a686354f8
m_ActionName: Player/Move[/XInputControllerWindows/leftStick,/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]
- m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 1214567908930553592}
m_TargetAssemblyTypeName: PlayerMovement, Assembly-CSharp
m_MethodName: OnJump
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_ActionId: eefb12f1-0980-4e79-a169-5b8d9c5f8909
m_ActionName: Player/Jump[/XInputControllerWindows/buttonSouth,/Keyboard/space]
- m_PersistentCalls:
@ -178,3 +205,40 @@ MonoBehaviour:
m_DefaultActionMap: Player
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!50 &945832017
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1214567908930553593}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 4
--- !u!58 &945832018
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1214567908930553593}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 6200000, guid: 72c8b57001d325c418a78771641a077f, type: 2}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.5

View File

@ -123,6 +123,165 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &412174278
GameObject:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 412174279}
- component: {fileID: 412174281}
- component: {fileID: 412174280}
m_Layer: 0
m_Name: cm
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &412174279
Transform:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 412174278}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.1217883, y: -1.235689, z: 10.669466}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 519903874}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &412174280
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 412174278}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6ad980451443d70438faac0bc6c235a0, type: 3}
m_Name:
m_EditorClassIdentifier:
m_TrackedObjectOffset: {x: 0, y: 0, z: 0}
m_LookaheadTime: 0
m_LookaheadSmoothing: 0
m_LookaheadIgnoreY: 0
m_XDamping: 1
m_YDamping: 1
m_ZDamping: 1
m_TargetMovementOnly: 1
m_ScreenX: 0.5
m_ScreenY: 0.5
m_CameraDistance: 10
m_DeadZoneWidth: 0
m_DeadZoneHeight: 0
m_DeadZoneDepth: 0
m_UnlimitedSoftZone: 0
m_SoftZoneWidth: 0.8
m_SoftZoneHeight: 0.8
m_BiasX: 0
m_BiasY: 0
m_CenterOnActivate: 1
m_GroupFramingMode: 2
m_AdjustmentMode: 0
m_GroupFramingSize: 0.8
m_MaxDollyIn: 5000
m_MaxDollyOut: 5000
m_MinimumDistance: 1
m_MaximumDistance: 5000
m_MinimumFOV: 3
m_MaximumFOV: 60
m_MinimumOrthoSize: 1
m_MaximumOrthoSize: 5000
--- !u!114 &412174281
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 412174278}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &519903872
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 519903874}
- component: {fileID: 519903873}
m_Layer: 0
m_Name: VCam
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &519903873
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519903872}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 45e653bab7fb20e499bda25e1b646fea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ExcludedPropertiesInInspector:
- m_Script
m_LockStageInInspector:
m_StreamingVersion: 20170927
m_Priority: 10
m_StandbyUpdate: 2
m_LookAt: {fileID: 1483024674}
m_Follow: {fileID: 1483024674}
m_Lens:
FieldOfView: 60
OrthographicSize: 5
NearClipPlane: 0.3
FarClipPlane: 1000
Dutch: 0
LensShift: {x: 0, y: 0}
m_Transitions:
m_BlendHint: 0
m_InheritPosition: 0
m_OnCameraLive:
m_PersistentCalls:
m_Calls: []
m_LegacyBlendHint: 0
m_ComponentOwner: {fileID: 412174279}
--- !u!4 &519903874
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519903872}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 412174279}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &1483024674 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1214567908930553594, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
m_PrefabInstance: {fileID: 1214567907777892293}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1798297288
GameObject:
m_ObjectHideFlags: 0
@ -135,6 +294,7 @@ GameObject:
- component: {fileID: 1798297290}
- component: {fileID: 1798297289}
- component: {fileID: 1798297292}
- component: {fileID: 1798297293}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@ -240,6 +400,112 @@ MonoBehaviour:
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
--- !u!114 &1798297293
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1798297288}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 72ece51f2901e7445ab60da3685d6b5f, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ShowDebugText: 0
m_ShowCameraFrustum: 1
m_IgnoreTimeScale: 0
m_WorldUpOverride: {fileID: 0}
m_UpdateMethod: 2
m_BlendUpdateMethod: 0
m_DefaultBlend:
m_Style: 1
m_Time: 2
m_CustomCurve:
serializedVersion: 2
m_Curve: []
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
m_CustomBlends: {fileID: 0}
m_CameraCutEvent:
m_PersistentCalls:
m_Calls: []
m_CameraActivatedEvent:
m_PersistentCalls:
m_Calls: []
--- !u!1 &2070667249
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2070667251}
- component: {fileID: 2070667250}
m_Layer: 0
m_Name: Global Light 2D
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2070667250
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2070667249}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 073797afb82c5a1438f328866b10b3f0, type: 3}
m_Name:
m_EditorClassIdentifier:
m_LightType: 4
m_BlendStyleIndex: 0
m_FalloffIntensity: 0.5
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_LightVolumeOpacity: 0
m_ApplyToSortingLayers: 00000000
m_LightCookieSprite: {fileID: 0}
m_UseNormalMap: 0
m_LightOrder: 0
m_AlphaBlendOnOverlap: 0
m_ShadowIntensity: 0
m_ShadowVolumeIntensity: 0
m_PointLightInnerAngle: 360
m_PointLightOuterAngle: 360
m_PointLightInnerRadius: 0
m_PointLightOuterRadius: 1
m_PointLightDistance: 3
m_PointLightQuality: 1
m_ShapeLightParametricSides: 5
m_ShapeLightParametricAngleOffset: 0
m_ShapeLightParametricRadius: 1
m_ShapeLightFalloffSize: 0.5
m_ShapeLightFalloffOffset: {x: 0, y: 0}
m_ShapePath:
- {x: -0.5, y: -0.5, z: 0}
- {x: 0.5, y: -0.5, z: 0}
- {x: 0.5, y: 0.5, z: 0}
- {x: -0.5, y: 0.5, z: 0}
--- !u!4 &2070667251
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2070667249}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.100620754, y: -0.46565726, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1214567907777892293
PrefabInstance:
m_ObjectHideFlags: 0
@ -253,7 +519,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 1214567908930553594, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
propertyPath: m_RootOrder
value: 1
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1214567908930553594, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
propertyPath: m_LocalPosition.x
@ -297,3 +563,60 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
--- !u!1001 &9196727425198912291
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9196727425507610131, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_Name
value: Arena
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5a9c2f4541a74e86afc424d568e0f629, type: 3}
m_Name: Player Stats
m_EditorClassIdentifier:
movementSpeed: 3
suckSpeed: 1
safeZoneJumpDuration: 1.2
safeZonePosition: {x: 0, y: 0, z: 0}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 12a626b5a296d934ba078d222ad6ba98
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,18 +1,181 @@
using System.Collections;
using System.Collections.Generic;
#nullable enable
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
public class PlayerMovement : MonoBehaviour {
[SerializeField] PlayerStats playerStats;
Rigidbody2D rb;
PlayerInput playerInput;
Vector2 moveDirection;
BaseState currentState = new ImmobileMovementState();
SafeZone? safeZone;
// Update is called once per frame
void Update()
{
}
}
bool lastJumpButton;
void Awake() {
rb = GetComponent<Rigidbody2D>();
playerInput = GetComponent<PlayerInput>();
}
void FixedUpdate() {
if (currentState.FixedUpdateState(this) is {} newState)
SwitchState(newState);
}
void OnDrawGizmos() => currentState.OnDrawGizmos(this);
public void OnMove(InputAction.CallbackContext ctx) {
moveDirection = ctx.ReadValue<Vector2>();
if (moveDirection.sqrMagnitude > 1.0f)
moveDirection.Normalize();
}
public void OnJump(InputAction.CallbackContext ctx) {
//feels pretty redundant ^^'
bool newValue = ctx.ReadValueAsButton();
bool wasJustPressed = !lastJumpButton && newValue;
lastJumpButton = newValue;
if (!wasJustPressed)
return;
if (safeZone == null)
return;
if (safeZone.IsInSafeZone) {
if (moveDirection.magnitude >= safeZone.stats.minJumpJoystickValue)
SwitchState(new ExitSafeZoneMovementState(safeZone, moveDirection));
} else //TODO if (AngleBetween(moveDirection, toSafeZone) < 90)
SwitchState(new EnterSafeZoneMovementState(safeZone));
}
void SwitchState(BaseState newState) {
currentState.LeaveState(this);
currentState = newState;
newState.EnterState(this);
}
void OnTriggerEnter2D(Collider2D other) {
if (other.GetComponent<SafeZone>() is {} triggeredSafeZone)
safeZone = triggeredSafeZone;
}
//Probably should remove, mostly for ImmobileState's draw gizmos
void OnTriggerStay2D(Collider2D other) {
if (other.GetComponent<SafeZone>() is {} triggeredSafeZone)
safeZone = triggeredSafeZone;
}
void OnTriggerExit2D(Collider2D other) {
if (other.GetComponent<SafeZone>() is {})
safeZone = null;
}
class BaseState {
public virtual void EnterState(PlayerMovement playerMovement) {}
public virtual void LeaveState(PlayerMovement playerMovement) {}
public virtual BaseState? UpdateState(PlayerMovement playerMovement) => null;
public virtual BaseState? FixedUpdateState(PlayerMovement playerMovement) => null;
public virtual void OnDrawGizmos(PlayerMovement playerMovement) {}
}
class NormalMovementState : BaseState {
public override BaseState? FixedUpdateState(PlayerMovement playerMovement) {
playerMovement.rb.velocity = (Vector3)playerMovement.moveDirection * playerMovement.playerStats.movementSpeed;
return null;
}
}
class JumpingMovementState : BaseState {
readonly float duration;
readonly Vector3 target;
Vector3 startPosition;
float startTime;
public JumpingMovementState(float duration, Vector3 target) {
this.duration = duration;
this.target = target;
}
public override void EnterState(PlayerMovement playerMovement) {
startPosition = playerMovement.transform.position;
startTime = Time.time;
playerMovement.rb.velocity = Vector2.zero;
}
public override BaseState? FixedUpdateState(PlayerMovement playerMovement) {
float currentTime = Time.time - startTime;
if (currentTime >= duration)
return Transition();
playerMovement.rb.MovePosition(Vector3.Lerp(
startPosition,
target,
CubicEaseOut(currentTime / duration)
));
return null;
}
protected virtual BaseState Transition() => new NormalMovementState();
static float CubicEaseOut(float t) => 1 - Mathf.Pow(1 - t, 3);
}
class EnterSafeZoneMovementState : JumpingMovementState {
readonly SafeZone safeZone;
public EnterSafeZoneMovementState(SafeZone safeZone) : base(safeZone.stats.jumpDuration, safeZone.transform.position) {
this.safeZone = safeZone;
}
public override void EnterState(PlayerMovement playerMovement) {
base.EnterState(playerMovement);
safeZone.EnterSafeZone();
playerMovement.rb.velocity = Vector2.zero;
}
protected override BaseState Transition() => new ImmobileMovementState();
}
class ExitSafeZoneMovementState : JumpingMovementState {
readonly SafeZone safeZone;
public ExitSafeZoneMovementState(SafeZone safeZone, Vector2 direction) : base(safeZone.stats.jumpDuration, safeZone.GetOutsidePosition(direction)) {
this.safeZone = safeZone;
}
public override void LeaveState(PlayerMovement playerMovement) {
base.EnterState(playerMovement);
safeZone.ExitSafeZone();
playerMovement.rb.velocity = Vector2.zero;
}
}
class ImmobileMovementState : BaseState {
#if UNITY_EDITOR
public override void OnDrawGizmos(PlayerMovement playerMovement) {
if (playerMovement.safeZone is null)
return;
Vector3 dropPosition = playerMovement.safeZone.GetOutsidePosition(playerMovement.moveDirection);
bool canJump = playerMovement.moveDirection.magnitude >= playerMovement.safeZone.stats.minJumpJoystickValue;
Gizmos.color = canJump ? Color.green : Color.red;
Gizmos.DrawLine(playerMovement.transform.position, dropPosition);
if (canJump)
Gizmos.DrawSphere(dropPosition, .5f);
else
Gizmos.DrawWireSphere(dropPosition, .5f);
}
#endif
}
}

View File

@ -0,0 +1,7 @@
using UnityEngine;
[CreateAssetMenu]
public class PlayerStats : ScriptableObject {
public float movementSpeed = 3f;
public float suckSpeed = 1f;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a9c2f4541a74e86afc424d568e0f629
timeCreated: 1648869672

View File

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7bb5b9d39d784569a22f3cf10d19c27b, type: 3}
m_Name: Safe Zone Stats
m_EditorClassIdentifier:
jumpDuration: 1.2

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 188711c0b201b1a45ad601ee20233b20
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using UnityEngine;
public class SafeZone : MonoBehaviour {
public SafeZoneStats stats;
[SerializeField] CircleCollider2D moatCollider;
public bool IsInSafeZone { get; private set; } = true;
public void EnterSafeZone() {
moatCollider.enabled = false;
IsInSafeZone = true;
}
public void ExitSafeZone() {
moatCollider.enabled = true;
IsInSafeZone = false;
}
public Vector3 GetOutsidePosition(Vector2 direction) {
return transform.position + (moatCollider.radius + stats.jumpOffset) * (Vector3)direction;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63e66d66543b37e419694ac22a2941fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
using UnityEngine;
[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;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7bb5b9d39d784569a22f3cf10d19c27b
timeCreated: 1648881833

View File

@ -0,0 +1,11 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!62 &6200000
PhysicsMaterial2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Zero Friction
friction: 0
bounciness: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 72c8b57001d325c418a78771641a077f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 6200000
userData:
assetBundleName:
assetBundleVariant: