Springboard & FallingPlatform
This commit is contained in:
8
Assets/Content/Prefabs/Platforms.meta
Normal file
8
Assets/Content/Prefabs/Platforms.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1eea2fe05d41514c99b6b5ac0de4e13
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
162
Assets/Content/Prefabs/Platforms/Rotating_Platform.prefab
Normal file
162
Assets/Content/Prefabs/Platforms/Rotating_Platform.prefab
Normal file
@@ -0,0 +1,162 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1001 &1964583291420173947
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 0.8470101
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalScale.y
|
||||
value: 2.1694
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalScale.z
|
||||
value: 6.981605
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -4.95
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 6.6
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: -8.08
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 0.70710653
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: -0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0.70710707
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: -0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 90
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: -8679921383154817045, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 919132149155446097, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: Rotating_Platform
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 919132149155446097, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_Layer
|
||||
value: 6
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 919132149155446097, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents:
|
||||
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 1352827198763262760}
|
||||
- targetCorrespondingSourceObject: {fileID: 919132149155446097, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 8141267412114706255}
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
--- !u!1 &1694184457223363370 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 3d620c9bb0ffa294392346026c6ab8cf, type: 3}
|
||||
m_PrefabInstance: {fileID: 1964583291420173947}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!65 &1352827198763262760
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1694184457223363370}
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_IsTrigger: 0
|
||||
m_ProvidesContacts: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &8141267412114706255
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1694184457223363370}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c27cc0f256617cc449b20ac4f9157740, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::ProceduralAnimator
|
||||
_settings:
|
||||
Space: 0
|
||||
Type: 0
|
||||
Balance: 1
|
||||
Curve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 1
|
||||
outSlope: 1
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 1
|
||||
outSlope: 1
|
||||
tangentMode: 34
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
Duration: 5
|
||||
TimeOffset: 0
|
||||
Translation: {x: 0, y: 0, z: 0}
|
||||
Rotation: {x: 0, y: 360, z: 0}
|
||||
Scale: {x: 0, y: 0, z: 0}
|
||||
_state:
|
||||
CurrentTime: 0
|
||||
IsFinished: 0
|
||||
InitialPosition: {x: 0, y: 0, z: 0}
|
||||
InitialRotation: {x: 0, y: 0, z: 0, w: 0}
|
||||
InitialScale: {x: 0, y: 0, z: 0}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4beaf6954e188347a7c1e7e772d364e
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
90
Assets/Content/Scripts/FallingPlatform.cs
Normal file
90
Assets/Content/Scripts/FallingPlatform.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class FallingPlatform : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
private class Settings
|
||||
{
|
||||
public float FallDelay = .5f;
|
||||
public float RecoverDelay = 5;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class References
|
||||
{
|
||||
public Rigidbody Rigidbody;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Settings _settings;
|
||||
|
||||
[SerializeField]
|
||||
private References _references;
|
||||
|
||||
int _originLayer;
|
||||
Vector3 _originPosition;
|
||||
Quaternion _originRotation;
|
||||
private IEnumerator _fallCoroutine;
|
||||
|
||||
void OnTriggerEnter(Collider col)
|
||||
{
|
||||
if (Player.Owner && Player.Owner.gameObject == col.gameObject)
|
||||
{
|
||||
Fall();
|
||||
}
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_originLayer = _references.Rigidbody.gameObject.layer;
|
||||
_originPosition = _references.Rigidbody.transform.position;
|
||||
_originRotation = _references.Rigidbody.transform.rotation;
|
||||
}
|
||||
|
||||
private void Fall()
|
||||
{
|
||||
if (_fallCoroutine != null)
|
||||
return;
|
||||
|
||||
StartCoroutine(_fallCoroutine = FallCoroutine());
|
||||
}
|
||||
|
||||
IEnumerator FallCoroutine()
|
||||
{
|
||||
yield return new WaitForSeconds(_settings.FallDelay);
|
||||
|
||||
Vector3 random = new Vector3(UnityEngine.Random.Range(-1, 1), UnityEngine.Random.Range(-1, 1), UnityEngine.Random.Range(-1, 1)).normalized;
|
||||
|
||||
_references.Rigidbody.isKinematic = false;
|
||||
_references.Rigidbody.AddRelativeTorque(random, ForceMode.Impulse);
|
||||
_references.Rigidbody.gameObject.layer = 0;
|
||||
|
||||
yield return new WaitForSeconds(_settings.RecoverDelay);
|
||||
|
||||
float duration = 1f;
|
||||
|
||||
_references.Rigidbody.isKinematic = true;
|
||||
_references.Rigidbody.gameObject.layer = _originLayer;
|
||||
|
||||
Vector3 originPosition = _references.Rigidbody.transform.position;
|
||||
Quaternion originRotation = _references.Rigidbody.transform.rotation;
|
||||
|
||||
for (float t = 0; t < duration; t += Time.deltaTime)
|
||||
{
|
||||
float normalizedTime = t / duration;
|
||||
float easeTime = .5f - Mathf.Cos(normalizedTime * Mathf.PI) * .5f;
|
||||
|
||||
_references.Rigidbody.transform.position = Vector3.Lerp(originPosition, _originPosition, easeTime);
|
||||
_references.Rigidbody.transform.rotation = Quaternion.Slerp(originRotation, _originRotation, easeTime);
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
_references.Rigidbody.transform.position = _originPosition;
|
||||
_references.Rigidbody.transform.rotation = _originRotation;
|
||||
|
||||
_fallCoroutine = null;
|
||||
}
|
||||
}
|
||||
2
Assets/Content/Scripts/FallingPlatform.cs.meta
Normal file
2
Assets/Content/Scripts/FallingPlatform.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4bf005511eccc940a19fd6bdbedc9bc
|
||||
@@ -588,8 +588,8 @@ public class Player : MonoBehaviour //NetworkBehaviour
|
||||
: PlayerState.Idle;
|
||||
}
|
||||
|
||||
if (_state.CurrentState != previousState)
|
||||
Debug.Log($"{previousState} → {_state.CurrentState}");
|
||||
//if (_state.CurrentState != previousState)
|
||||
// Debug.Log($"{previousState} → {_state.CurrentState}");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
20
Assets/Content/Scripts/Springboard.cs
Normal file
20
Assets/Content/Scripts/Springboard.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class Springboard : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float _force = 60;
|
||||
[SerializeField] private float _duration = .4f;
|
||||
[SerializeField] private AnimationCurve _curve = AnimationCurve.EaseInOut(0, 1, 1, 0);
|
||||
[SerializeField] private UnityEvent _onJump;
|
||||
|
||||
void OnTriggerEnter(Collider col)
|
||||
{
|
||||
if (Player.Owner && col.gameObject == Player.Owner.gameObject)
|
||||
{
|
||||
Debug.Log("Player triggered springboard");
|
||||
Player.Owner.AddExtraForce(Vector3.up * _force, true, _duration, _curve);
|
||||
_onJump?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Content/Scripts/Springboard.cs.meta
Normal file
2
Assets/Content/Scripts/Springboard.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: effa7acb4388bcf4381294d9134d23f6
|
||||
Reference in New Issue
Block a user