- Home /
Question by
mattbullen18 · May 02, 2020 at 01:41 PM ·
fixedjoint
I need to remove FixedJoint2D when the mouse button is released, thanks.
My Code
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class stickToPlatforms : MonoBehaviour { private Rigidbody2D rb;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Platform")
{
rb = this.GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(0,0);
var joint = gameObject.AddComponent<FixedJoint2D>();
joint.connectedBody = collision.gameObject.GetComponent<Rigidbody2D>();
if (Input.GetMouseButtonUp(0))
{
Destroy(joint.connectedBody);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Connect 2 rigidbodies 0 Answers
Rotation of object is effecting my FixedJoint2D anchoring point. 0 Answers
FixedJoint seems glitchy 0 Answers