Rope lerps to grapple point
This commit is contained in:
parent
62267b6f2e
commit
92be2fc57f
@ -8,7 +8,9 @@ public class GrappleHook : MonoBehaviour
|
||||
[SerializeField]
|
||||
private float maxGrappleDist = 200;
|
||||
[SerializeField]
|
||||
private LayerMask grappleableLayer; // TODO create layermask
|
||||
private float grappleExtendSpeed = 20;
|
||||
[SerializeField]
|
||||
private LayerMask grappleableLayer;
|
||||
[SerializeField]
|
||||
private Transform gunPos;
|
||||
private Vector3 hitPosLocal;
|
||||
@ -16,6 +18,7 @@ public class GrappleHook : MonoBehaviour
|
||||
private LineRenderer lr;
|
||||
RaycastHit hit;
|
||||
private bool grappled = false;
|
||||
private Vector3 currGrappleEndPos;
|
||||
[SerializeField]
|
||||
private Transform hitMarker; //TODO obj this should be a sprite or something idk
|
||||
// Start is called before the first frame update
|
||||
@ -35,7 +38,7 @@ public class GrappleHook : MonoBehaviour
|
||||
EndGrapple();
|
||||
}
|
||||
if(grappled){
|
||||
DrawRope();
|
||||
DrawRope(Time.deltaTime);
|
||||
if(Input.GetMouseButtonDown(1)){
|
||||
joint.minDistance = 0f;
|
||||
joint.maxDistance = 0f;
|
||||
@ -61,16 +64,19 @@ public class GrappleHook : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRope(){
|
||||
private void DrawRope(float deltaTime){
|
||||
// TODO animate a wiggle on the rope
|
||||
if(!grappled)return;
|
||||
// TODO Draw gradually towards point
|
||||
lr.SetPosition(0, gunPos.position);
|
||||
Vector3 endPoint;
|
||||
if(hit.rigidbody != null){
|
||||
lr.SetPosition(1, hit.transform.TransformPoint(hitPosLocal));
|
||||
endPoint = hit.transform.TransformPoint(hitPosLocal);
|
||||
|
||||
}else{
|
||||
lr.SetPosition(1, hit.point);
|
||||
endPoint = hit.point;
|
||||
}
|
||||
|
||||
currGrappleEndPos = Vector3.Lerp(currGrappleEndPos, endPoint, deltaTime * grappleExtendSpeed);
|
||||
lr.SetPosition(1, currGrappleEndPos);
|
||||
if(!lr.enabled)lr.enabled = true;
|
||||
|
||||
}
|
||||
@ -97,11 +103,14 @@ public class GrappleHook : MonoBehaviour
|
||||
joint.spring = 4.5f * 5f;
|
||||
joint.damper = 7f;
|
||||
joint.massScale = 4.5f;
|
||||
|
||||
currGrappleEndPos = transform.position;
|
||||
}
|
||||
|
||||
private void EndGrapple(){
|
||||
grappled = false;
|
||||
lr.enabled = false;
|
||||
|
||||
Destroy(joint);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user