Can grapple objects with rigidbodies
This commit is contained in:
parent
e42f7e8f81
commit
62267b6f2e
@ -10,7 +10,8 @@ public class GrappleHook : MonoBehaviour
|
||||
[SerializeField]
|
||||
private LayerMask grappleableLayer; // TODO create layermask
|
||||
[SerializeField]
|
||||
private Vector3 gunPos = new Vector3 (-0.5f, 0f, 0f);
|
||||
private Transform gunPos;
|
||||
private Vector3 hitPosLocal;
|
||||
private SpringJoint joint;
|
||||
private LineRenderer lr;
|
||||
RaycastHit hit;
|
||||
@ -63,8 +64,13 @@ public class GrappleHook : MonoBehaviour
|
||||
private void DrawRope(){
|
||||
if(!grappled)return;
|
||||
// TODO Draw gradually towards point
|
||||
lr.SetPosition(0, gameObject.transform.position);
|
||||
lr.SetPosition(1, hit.point);
|
||||
lr.SetPosition(0, gunPos.position);
|
||||
if(hit.rigidbody != null){
|
||||
lr.SetPosition(1, hit.transform.TransformPoint(hitPosLocal));
|
||||
}else{
|
||||
lr.SetPosition(1, hit.point);
|
||||
}
|
||||
|
||||
if(!lr.enabled)lr.enabled = true;
|
||||
|
||||
}
|
||||
@ -75,11 +81,19 @@ public class GrappleHook : MonoBehaviour
|
||||
hitMarker.gameObject.SetActive(false);
|
||||
|
||||
joint = gameObject.AddComponent<SpringJoint>();
|
||||
joint.anchor = gunPos;
|
||||
joint.anchor = transform.InverseTransformPoint(gunPos.position);
|
||||
joint.autoConfigureConnectedAnchor = false;
|
||||
joint.maxDistance = hit.distance * 0.8f;
|
||||
joint.minDistance = hit.distance * 0.25f;
|
||||
joint.connectedAnchor = hit.point;
|
||||
if(hit.rigidbody != null){
|
||||
Rigidbody hitRb = hit.rigidbody;
|
||||
joint.connectedBody = hitRb;
|
||||
joint.connectedAnchor = hit.transform.InverseTransformPoint(hit.point);
|
||||
hitPosLocal = hit.transform.InverseTransformPoint(hit.point);
|
||||
}else{
|
||||
joint.connectedAnchor = hit.point;
|
||||
}
|
||||
|
||||
joint.spring = 4.5f * 5f;
|
||||
joint.damper = 7f;
|
||||
joint.massScale = 4.5f;
|
||||
|
||||
@ -234,13 +234,13 @@ Rigidbody:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 617391188}
|
||||
serializedVersion: 2
|
||||
m_Mass: 0.1
|
||||
m_Mass: 0.01
|
||||
m_Drag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 0
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_Constraints: 40
|
||||
m_CollisionDetection: 0
|
||||
--- !u!135 &617391190
|
||||
SphereCollider:
|
||||
@ -623,7 +623,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1094313414}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 10.16, y: 6.77, z: 0}
|
||||
m_LocalPosition: {x: 6.33, y: 6.77, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -757,7 +757,7 @@ Rigidbody:
|
||||
m_GameObject: {fileID: 1211811536}
|
||||
serializedVersion: 2
|
||||
m_Mass: 1
|
||||
m_Drag: 0
|
||||
m_Drag: 0.01
|
||||
m_AngularDrag: 0.05
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user