Commit 2314940d authored by 15박보승's avatar 15박보승

훅의 최대거리 제한 구현

parent df67be5d
...@@ -342,6 +342,7 @@ MonoBehaviour: ...@@ -342,6 +342,7 @@ MonoBehaviour:
lr: {fileID: 48712148} lr: {fileID: 48712148}
player: {fileID: 1171556388} player: {fileID: 1171556388}
rb: {fileID: 0} rb: {fileID: 0}
maxDistance: 200
--- !u!1 &60348332 --- !u!1 &60348332
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -12,7 +12,12 @@ public class HookBehaviour : MonoBehaviour ...@@ -12,7 +12,12 @@ public class HookBehaviour : MonoBehaviour
[SerializeField] [SerializeField]
private Rigidbody rb; private Rigidbody rb;
private void OnDrawGizmos() [SerializeField]
private float maxDistance;
private float curDistance;
private void OnDrawGizmos()
{ {
} }
...@@ -29,6 +34,17 @@ public class HookBehaviour : MonoBehaviour ...@@ -29,6 +34,17 @@ public class HookBehaviour : MonoBehaviour
lr.SetPosition(1, player.position); lr.SetPosition(1, player.position);
} }
private void FixedUpdate()
{
Debug.Log(curDistance);
if (curDistance <= maxDistance)
{
curDistance += rb.velocity.magnitude * Time.fixedDeltaTime;
if (curDistance > maxDistance)
player.GetComponent<PlayerController>().ReturnHook();
}
}
private void OnCollisionEnter(Collision collision) private void OnCollisionEnter(Collision collision)
{ {
rb.velocity = Vector3.zero; rb.velocity = Vector3.zero;
...@@ -43,6 +59,7 @@ public class HookBehaviour : MonoBehaviour ...@@ -43,6 +59,7 @@ public class HookBehaviour : MonoBehaviour
lr.SetPosition(1, player.position); lr.SetPosition(1, player.position);
rb.isKinematic = false; rb.isKinematic = false;
rb.velocity = velocity; rb.velocity = velocity;
curDistance = 0;
} }
public void DisableHook() public void DisableHook()
......
...@@ -36,6 +36,7 @@ public class PlayerController : MonoBehaviour ...@@ -36,6 +36,7 @@ public class PlayerController : MonoBehaviour
[SerializeField] [SerializeField]
private LayerMask enemyMask; private LayerMask enemyMask;
#if UNITY_EDITOR #if UNITY_EDITOR
private void OnDrawGizmos() private void OnDrawGizmos()
{ {
...@@ -120,7 +121,7 @@ public class PlayerController : MonoBehaviour ...@@ -120,7 +121,7 @@ public class PlayerController : MonoBehaviour
hook.EnableHook(Camera.main.transform.forward.normalized * 200); hook.EnableHook(Camera.main.transform.forward.normalized * 200);
} }
private void ReturnHook() public void ReturnHook()
{ {
joint.enabled = false; joint.enabled = false;
hook.DisableHook(); hook.DisableHook();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment