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