cleaned up scripts a little bit

This commit is contained in:
slevy14 2023-04-17 16:47:12 -07:00
parent 275763628b
commit cb059613f9
7 changed files with 170 additions and 346 deletions

View File

@ -102,7 +102,7 @@ Material:
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _LightingEnabled: 0
- _LightingEnabled: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1

View File

@ -15,6 +15,7 @@ GameObject:
- component: {fileID: 5885597207104481990}
- component: {fileID: 5885597207104481984}
- component: {fileID: 1407172087}
- component: {fileID: 3893791749692807526}
- component: {fileID: 5559747613460074786}
m_Layer: 2
m_Name: Player
@ -219,12 +220,59 @@ MonoBehaviour:
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_ActionEvents: []
m_ActionEvents:
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 5559747613460074786}
m_TargetAssemblyTypeName: PlayerMovement, Assembly-CSharp
m_MethodName: OnGrapple
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: 183693a0-ab31-4f85-a4ef-b43b8a80fa77
m_ActionName: Player/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 2116b59e-20ee-4f7c-a656-aad81b0ae23a
m_ActionName: Player/Grapple[/Keyboard/l]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 00940c0e-3199-4943-a074-8cde87588db2
m_ActionName: Player/ThrowTambourine[/Keyboard/k]
- m_PersistentCalls:
m_Calls: []
m_ActionId: 5a10231f-97fe-4bfb-89d8-4ac906d76de6
m_ActionName: Player/Jump[/Keyboard/space]
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: Player
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!114 &3893791749692807526
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5885597207104481991}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b0115312556794123a3cafad4b83d0a7, type: 3}
m_Name:
m_EditorClassIdentifier:
playerInput: {fileID: 1407172087}
launcher: {fileID: 6559806128767475056}
hasTambourine: 1
grapplingGun: {fileID: 3465910379319867675}
grapplingRope: {fileID: 7648135587659148198}
playerController: {fileID: 5559747613460074786}
stateController: {fileID: 0}
--- !u!114 &5559747613460074786
MonoBehaviour:
m_ObjectHideFlags: 0
@ -247,8 +295,6 @@ MonoBehaviour:
m_Bits: 64
boxSize: {x: 0.03, y: 0.21}
maxDistanceFromGround: 0.13
grapplingGun: {fileID: 3465910379319867675}
grapplingRope: {fileID: 7648135587659148198}
stateController: {fileID: 0}
--- !u!1 &5885597207531562995
GameObject:
@ -357,7 +403,7 @@ SpriteRenderer:
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_SortingOrder: 1
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Color: {r: 0.64606833, g: 1, b: 0, a: 1}
m_FlipX: 0
@ -528,7 +574,7 @@ LineRenderer:
- {x: 0, y: 0, z: 1}
m_Parameters:
serializedVersion: 3
widthMultiplier: 0.15
widthMultiplier: 0.1
widthCurve:
serializedVersion: 2
m_Curve:
@ -593,7 +639,7 @@ Rigidbody2D:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5885597207789090697}
m_BodyType: 0
m_BodyType: 1
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
@ -686,7 +732,7 @@ MonoBehaviour:
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0.0012016296
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
@ -696,7 +742,7 @@ MonoBehaviour:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
startWaveSize: 2
startWaveSize: 4
ropeProgressionCurve:
serializedVersion: 2
m_Curve:

View File

@ -188,17 +188,6 @@ MonoBehaviour:
player: {fileID: 5885597207104481991, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
spawnPoint: {fileID: 1159415542}
deathCanvas: {fileID: 880696833}
--- !u!114 &129360812 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 3465910379319867675, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
m_PrefabInstance: {fileID: 1407172085}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6e8c21a2613bf4423a2f49601a3310e3, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &193907867
GameObject:
m_ObjectHideFlags: 0
@ -1364,7 +1353,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -25.56, y: -10.43, z: -10}
m_LocalPosition: {x: -24.31, y: -10.73, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -2325,82 +2314,10 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_NotificationBehavior
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.size
value: 4
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_ActionId
value: 183693a0-ab31-4f85-a4ef-b43b8a80fa77
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[1].m_ActionId
value: 2116b59e-20ee-4f7c-a656-aad81b0ae23a
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[2].m_ActionId
value: 00940c0e-3199-4943-a074-8cde87588db2
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[3].m_ActionId
value: 5a10231f-97fe-4bfb-89d8-4ac906d76de6
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_ActionName
value: Player/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[1].m_ActionName
value: Player/Grapple[/Keyboard/l]
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[2].m_ActionName
value: Player/ThrowTambourine[/Keyboard/k]
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[3].m_ActionName
value: Player/Jump[/Keyboard/space]
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_PersistentCalls.m_Calls.Array.size
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_PersistentCalls.m_Calls.Array.data[0].m_Mode
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 1787574353}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_PersistentCalls.m_Calls.Array.data[0].m_CallState
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: OnGrapple
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
value: PlayerMovement, Assembly-CSharp
objectReference: {fileID: 0}
- target: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_ActionEvents.Array.data[0].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
value: UnityEngine.Object, UnityEngine
objectReference: {fileID: 0}
- target: {fileID: 3465910379319867675, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_camera
value:
objectReference: {fileID: 519420031}
- target: {fileID: 5559747613460074786, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: launcher
value:
objectReference: {fileID: 2001713740}
- target: {fileID: 5885597207104481986, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
propertyPath: m_RootOrder
value: 13
@ -2452,10 +2369,7 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 5885597207104481991, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
insertIndex: 7
addedObject: {fileID: 1787574362}
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
--- !u!1 &1411598161
GameObject:
@ -3259,60 +3173,6 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1767983939}
m_CullTransparentMesh: 1
--- !u!1 &1787574352 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5885597207104481991, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
m_PrefabInstance: {fileID: 1407172085}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1787574353 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5559747613460074786, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
m_PrefabInstance: {fileID: 1407172085}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1787574352}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7b873819f9a3f36ef898a0403972da28, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1787574354 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1407172087, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
m_PrefabInstance: {fileID: 1407172085}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1787574352}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1787574362
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1787574352}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b0115312556794123a3cafad4b83d0a7, type: 3}
m_Name:
m_EditorClassIdentifier:
moveSpeed: 0
jumpSpeed: 0
airSpeed: 0
playerInput: {fileID: 1787574354}
groundLayer:
serializedVersion: 2
m_Bits: 64
boxSize: {x: 0, y: 0}
maxDistanceFromGround: 0
launcher: {fileID: 2001713740}
hasTambourine: 1
grapplingGun: {fileID: 129360812}
grapplingRope: {fileID: 2119213706}
playerController: {fileID: 1787574353}
stateController: {fileID: 0}
--- !u!1 &1796403731
GameObject:
m_ObjectHideFlags: 0
@ -10177,43 +10037,79 @@ CompositeCollider2D:
Y: -63125000
m_CompositePaths:
m_Paths:
- - {x: 21, y: -18.882843}
- {x: 21, y: -11.117158}
- {x: 20.882843, y: -11}
- {x: -18.882843, y: -11}
- {x: -19, y: -11.117158}
- {x: -19, y: -16.882843}
- {x: -19.117157, y: -17}
- {x: -27.882841, y: -17}
- {x: -28, y: -16.882843}
- {x: -28, y: -11.117158}
- {x: -28.117159, y: -11}
- {x: -36.882843, y: -11}
- {x: -37, y: -10.882842}
- {x: -37, y: 10.882842}
- {x: -37.117157, y: 11}
- {x: -38, y: 10.882842}
- {x: -38, y: -18.882843}
- {x: -37.882843, y: -19}
- {x: 20.882843, y: -19}
- - {x: -21.117157, y: -6.25}
- {x: -20.882843, y: -6}
- {x: 8.882842, y: -6}
- {x: 9, y: -5.882843}
- {x: 9, y: -1.8268197}
- {x: 2.2543635, y: -4.018818}
- {x: 0.5492318, y: -4.3823714}
- {x: -0.1171574, y: -5}
- {x: -8.882842, y: -5}
- {x: -9.117158, y: -3}
- {x: -34.882843, y: -3}
- {x: -35, y: -3.1171572}
- {x: -35, y: -5.882843}
- {x: -34.882843, y: -6}
- {x: -26.117157, y: -6}
- {x: -25.882843, y: -6.25}
- - {x: 21, y: -11}
- {x: -19, y: -11}
- {x: -19, y: -17}
- {x: -28, y: -17}
- {x: -28, y: -11}
- {x: -37, y: -11}
- {x: -37, y: 11}
- {x: -38, y: 11}
- {x: -38, y: -19}
- {x: 21, y: -19}
- - {x: -25, y: -6.25}
- {x: -24.8125, y: -6.3125}
- {x: -24.09375, y: -6.3125}
- {x: -24, y: -6.25}
- {x: -23.8125, y: -6.3125}
- {x: -23.09375, y: -6.3125}
- {x: -23, y: -6.25}
- {x: -22.8125, y: -6.3125}
- {x: -22.09375, y: -6.3125}
- {x: -22, y: -6.25}
- {x: -21.8125, y: -6.3125}
- {x: -21.09375, y: -6.3125}
- {x: -21, y: -6.25}
- {x: -21, y: -6}
- {x: 9, y: -6}
- {x: 9, y: -1.6875}
- {x: 8.75, y: -1.6875}
- {x: 8.343751, y: -1.78125}
- {x: 8.343751, y: -2}
- {x: 8.0625, y: -2}
- {x: 8, y: -2.0625}
- {x: 8, y: -2.09375}
- {x: 7.375, y: -2.09375}
- {x: 7, y: -2.3125}
- {x: 7, y: -2.34375}
- {x: 6.9687505, y: -2.34375}
- {x: 6.5625, y: -2.375}
- {x: 6, y: -2.6875}
- {x: 5.75, y: -2.6875}
- {x: 5.34375, y: -2.78125}
- {x: 5.34375, y: -3}
- {x: 5.0625, y: -3}
- {x: 5, y: -3.0625}
- {x: 5, y: -3.09375}
- {x: 4.375, y: -3.09375}
- {x: 4, y: -3.3125}
- {x: 4, y: -3.34375}
- {x: 3.96875, y: -3.34375}
- {x: 3.5625, y: -3.375}
- {x: 3, y: -3.6875}
- {x: 2.75, y: -3.6875}
- {x: 2.34375, y: -3.78125}
- {x: 2.34375, y: -4}
- {x: 2.0625, y: -4}
- {x: 2, y: -4.0625}
- {x: 2, y: -4.09375}
- {x: 1.375, y: -4.09375}
- {x: 1, y: -4.3125}
- {x: 1, y: -4.34375}
- {x: 0.96875, y: -4.34375}
- {x: 0.5625, y: -4.375}
- {x: 0, y: -4.6875}
- {x: 0, y: -5}
- {x: -9, y: -5}
- {x: -9, y: -3}
- {x: -35, y: -3}
- {x: -35, y: -6}
- {x: -26, y: -6}
- {x: -26, y: -6.25}
- {x: -25.8125, y: -6.3125}
- {x: -25.09375, y: -6.3125}
m_VertexDistance: 0.11
m_OffsetDistance: 0.2
m_OffsetDistance: 0
m_UseDelaunayMesh: 1
m_CompositeGameObject: {fileID: 1818375521}
--- !u!50 &1818375527
@ -10585,17 +10481,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2001713740 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 6559806128767475056, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
m_PrefabInstance: {fileID: 1407172085}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b49ff353512cc43728014da636fce388, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2026489080
GameObject:
m_ObjectHideFlags: 0
@ -10708,14 +10593,3 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5e69412b9141e4bdeaaaf00f6dce7b82, type: 3}
--- !u!114 &2119213706 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7648135587659148198, guid: 576d3fc87874f426294e4bbacb171478, type: 3}
m_PrefabInstance: {fileID: 1407172085}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 06317215013e44d0fb7902fbc1c5e84e, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -7,18 +7,11 @@ public class PlayerBehavior : MonoBehaviour
{
[Header("Physics:")]
public float moveSpeed;
public float jumpSpeed;
public float airSpeed;
private float _hInput;
private Rigidbody2D _rb;
private int forward = 1;
public PlayerInput playerInput;
public LayerMask groundLayer;
public Vector2 boxSize;
public float maxDistanceFromGround;
[Header("Tambourine:")]
[SerializeField] private Launch launcher;
[HideInInspector] public bool hasTambourine = true;
@ -37,7 +30,6 @@ public class PlayerBehavior : MonoBehaviour
void Start()
{
_rb = GetComponent<Rigidbody2D>();
airSpeed = .5f * moveSpeed;
stateController = GameObject.Find("StateController").GetComponent<StateController>();
}
@ -112,4 +104,25 @@ public class PlayerBehavior : MonoBehaviour
}
grapplingGun.ReleaseGrapple();
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "grappleSurface")
{
grappleSurface = col.gameObject;
}
else if (col.tag == "instaDeath")
{
this.stateController.SetDeathCanvasActive(true);
Destroy(this.gameObject);
}
}
void OnTriggerExit2D(Collider2D col)
{
if (col.tag == "grappleSurface")
{
grappleSurface = null;
}
}
}

View File

@ -23,18 +23,11 @@ public class PlayerMovement : MonoBehaviour
public Vector2 boxSize;
public float maxDistanceFromGround;
[Header("Grappling:")]
[SerializeField] public Tutorial_GrapplingGun grapplingGun;
[SerializeField] public Tutorial_GrapplingRope grapplingRope;
private GameObject grappleSurface;
[Header("Tambourine:")]
[SerializeField] private Launch launcher;
[HideInInspector] public bool hasTambourine = true;
[Header("State Control:")]
[SerializeField] private StateController stateController;
PlayerBehavior playerBehavior;
void OnValidate()
{
this.runAcceleration = Mathf.Clamp(runAcceleration, 0.1f, this.maxRunSpeed);
@ -42,6 +35,7 @@ public class PlayerMovement : MonoBehaviour
void Start()
{
playerBehavior = this.gameObject.GetComponent<PlayerBehavior>();
this.rb = this.GetComponent<Rigidbody2D>();
stateController = GameObject.Find("StateController").GetComponent<StateController>();
}
@ -88,14 +82,16 @@ public class PlayerMovement : MonoBehaviour
float frictionAmount = 0.5f;
// accelerate
if (onGround && (Mathf.Abs(this.movement.x) > 0.1f)) {
if (onGround && (Mathf.Abs(this.movement.x) > 0.1f)) { // regular acceleration
this.rb.AddForce(move * Vector2.right, ForceMode2D.Force);
} else if (!onGround && (Mathf.Abs(this.movement.x) > 0.1f)) {
} else if (!onGround && (Mathf.Abs(this.movement.x) > 0.1f) && !playerBehavior.grapplingRope.isGrappling) { // while in air
this.rb.AddForce(move * Vector2.right * airSpeedMultiplier, ForceMode2D.Force);
} else if (!playerBehavior.grapplingRope.isGrappling) { // while grappling
this.rb.AddForce(move * Vector2.right * airSpeedMultiplier * airSpeedMultiplier, ForceMode2D.Force);
}
// decelerate until stopped
if (Mathf.Abs(this.movement.x) < 0.1f)
if (onGround && Mathf.Abs(this.movement.x) < 0.1f)
{
if (Mathf.Abs(rb.velocity.x) > 0.1f) {
float amount = Mathf.Min(
@ -110,27 +106,6 @@ public class PlayerMovement : MonoBehaviour
}
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "grappleSurface")
{
grappleSurface = col.gameObject;
}
else if (col.tag == "instaDeath")
{
this.stateController.SetDeathCanvasActive(true);
Destroy(this.gameObject);
}
}
void OnTriggerExit2D(Collider2D col)
{
if (col.tag == "grappleSurface")
{
grappleSurface = null;
}
}
bool IsGrounded()
{
if (Physics2D.BoxCast(transform.position, boxSize, 0, -transform.up, maxDistanceFromGround, groundLayer))

View File

@ -25,22 +25,12 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
[SerializeField] private bool rotateOverTime = true;
[Range(0, 60)][SerializeField] private float rotationSpeed = 4;
[Header("Distance:")]
[SerializeField] private bool hasMaxDistance = false;
[SerializeField] private float maxDistance = 20;
private enum LaunchType {
TransformLaunch,
PhysicsLaunch
}
[Header("Launching:")]
[SerializeField] private bool launchToPoint = true;
[SerializeField] private LaunchType launchType = LaunchType.PhysicsLaunch;
[SerializeField] private float launchSpeed = 1;
[Header("No Launch To Point")]
[SerializeField] private bool autoConfigureDistance = false;
[SerializeField] private float targetDistance = 3;
[SerializeField] private float targetFrequency = 1;
@ -60,32 +50,12 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
}
void Update() {
// if (Input.GetKeyDown(KeyCode.Mouse0)) {
// SetGrapplePoint();
// } else if (Input.GetKey(KeyCode.Mouse0)) {
// if (grappleRope.enabled) {
// RotateGun(grapplePoint, false);
// } else {
// Vector2 mousePos = m_camera.ScreenToWorldPoint(Input.mousePosition);
// RotateGun(mousePos, true);
// }
// if (launchToPoint && grappleRope.isGrappling) {
// if (launchType == LaunchType.TransformLaunch) {
// Vector2 firePointDistance = firePoint.position - gunHolder.localPosition;
// Vector2 targetPos = grapplePoint - firePointDistance;
// gunHolder.position = Vector2.Lerp(gunHolder.position, targetPos, Time.deltaTime * launchSpeed);
// }
// }
// } else if (Input.GetKeyUp(KeyCode.Mouse0)) {
// ReleaseGrapple();
// } else {
Vector2 mousePos = m_camera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
RotateGun(mousePos, true);
// }
Vector2 mousePos = m_camera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
RotateGun(mousePos, true);
if (grappleRope.isGrappling && !inDistanceRange && Vector2.Distance(grapplePoint, new Vector2(m_rigidBody2D.transform.position.x, m_rigidBody2D.transform.position.y)) < targetDistance) {
print(Vector2.Distance(grapplePoint, new Vector2(m_rigidBody2D.transform.position.x, m_rigidBody2D.transform.position.y)) + ", target: " + targetDistance);
// print(Vector2.Distance(grapplePoint, new Vector2(m_rigidBody2D.transform.position.x, m_rigidBody2D.transform.position.y)) + ", target: " + targetDistance);
inDistanceRange = true;
}
if (inDistanceRange) {
@ -105,65 +75,17 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
}
// void SetGrapplePoint() {
// Vector2 distanceVector = m_camera.ScreenToWorldPoint(Input.mousePosition) - gunPivot.position;
// // print("clicked" + m_camera.ScreenToWorldPoint(Input.mousePosition));
// // print("distance vector: " + distanceVector);
// if (Physics2D.Raycast(firePoint.position, distanceVector.normalized)) {
// RaycastHit2D _hit = Physics2D.Raycast(firePoint.position, distanceVector.normalized);
// print(_hit.transform.gameObject.name);
// if (_hit.transform.gameObject.layer == grappleLayerNumber || grappleToAll) {
// if (Vector2.Distance(_hit.point, firePoint.position) <= maxDistance || !hasMaxDistance) {
// // print("gunPivot " + gunPivot.position + ", grappling to: " + _hit.point);
// grapplePoint = _hit.point;
// grappleDistanceVector = grapplePoint - (Vector2)gunPivot.position;
// grappleRope.enabled = true;
// }
// }
// }
// }
public void Grapple() {
print("grapple");
// print("grapple");
m_springJoint2D.autoConfigureDistance = false;
m_distanceJoint2D.autoConfigureDistance = false;
if(!launchToPoint && !autoConfigureDistance) {
m_springJoint2D.distance = targetDistance;
print("Sprint Joint Distance:" + m_springJoint2D.distance);
m_springJoint2D.frequency = targetFrequency;
}
if (!launchToPoint) {
if (autoConfigureDistance) {
m_springJoint2D.connectedAnchor = grapplePoint;
m_springJoint2D.enabled = true;
// print("Spring Joint Enabled");
print("Sprint Joint Distance:" + m_springJoint2D.distance);
m_springJoint2D.connectedAnchor = grapplePoint;
m_springJoint2D.enabled = true;
// print("Spring Joint Enabled");
// print("Sprint Joint Distance:" + m_springJoint2D.distance);
m_distanceJoint2D.connectedAnchor = grapplePoint;
}
} else {
switch (launchType) {
case LaunchType.PhysicsLaunch:
m_springJoint2D.connectedAnchor = grapplePoint;
m_distanceJoint2D.connectedAnchor = grapplePoint;
Vector2 distanceVector = firePoint.position - gunHolder.position;
m_springJoint2D.distance = distanceVector.magnitude;
m_springJoint2D.frequency = launchSpeed;
m_springJoint2D.enabled = true;
// m_distanceJoint2D.maxDistanceOnly = false;
m_distanceJoint2D.distance = targetDistance + .5f;
break;
case LaunchType.TransformLaunch:
m_rigidBody2D.gravityScale = 0;
m_rigidBody2D.velocity = Vector2.zero;
break;
}
}
m_distanceJoint2D.connectedAnchor = grapplePoint;
}
public void GrappleToTambourine(GameObject tambourine) {
@ -209,11 +131,4 @@ public class Tutorial_GrapplingGun : MonoBehaviour {
// print("disabled");
}
private void OnDrawGizmosSelected() {
if (firePoint != null && hasMaxDistance) {
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(firePoint.position, maxDistance);
}
}
}

View File

@ -62,7 +62,7 @@ public class Tutorial_GrapplingRope : MonoBehaviour {
if (!straightLine) {
float roundedLinePos = Mathf.Round(m_lineRenderer.GetPosition(precision - 1).x * 10.0f) * .01f;
float roundedGrapplePos = Mathf.Round(m_lineRenderer.GetPosition(precision - 1).x * 10.0f) * .01f;
print(roundedLinePos + " / " + roundedGrapplePos);
// print(roundedLinePos + " / " + roundedGrapplePos);
if (roundedLinePos == roundedGrapplePos) {
straightLine = true;
} else {
@ -87,6 +87,7 @@ public class Tutorial_GrapplingRope : MonoBehaviour {
}
void DrawRopeWaves() {
print(moveTime);
for (int i = 0; i < precision; i++) {
float delta = (float)i / ((float)precision - 1f);
Vector2 offset = Vector2.Perpendicular(grapplingGun.grappleDistanceVector).normalized * ropeAnimationCurve.Evaluate(delta) * waveSize;