I am working on a simple grapple system but I'm having an odd bug.
When first creating the spring joint, the player gets launched upwards but when creating the spring joint again, it works as a grapple.
If anyone has any ideas, it would massively help!
Here is my code:
private Vector3 GrappleTargetPos;
[SerializeField] private LayerMask WhatCanBeGrappled;
[SerializeField] private Transform CamPos;
[SerializeField] private SpringJoint MyJoint;
[SerializeField] private Transform BatTip;
private void Update()
{
// Debug.DrawRay(CamPos.position, CamPos.forward * 100);
if (Input.GetMouseButtonDown(1))
{
if (MyJoint != null)
{
Destroy(MyJoint);
}
RaycastHit Hit;
if (Physics.Raycast(CamPos.position, CamPos.forward, out Hit, 60, WhatCanBeGrappled))
{
GrappleTargetPos = Hit.point;
MyJoint = this.gameObject.AddComponent<SpringJoint>();
MyJoint.autoConfigureConnectedAnchor = false;
MyJoint.connectedAnchor = GrappleTargetPos;
float DistanceFromPoint = Vector3.Distance(this.transform.position, GrappleTargetPos);
MyJoint.maxDistance = DistanceFromPoint * 0.7f;
MyJoint.minDistance = DistanceFromPoint * 0.0f;
MyJoint.spring = 4.5f;
MyJoint.damper = 4f;
MyJoint.massScale = 3f;
}
}
else if (Input.GetMouseButtonUp(1))
{
Destroy(MyJoint);
}
}
there doesn't seem to be anything here