I updated to 5.3.4f1 today because of the fix to the bug related to TargetJoint2D not activating colliders when instantiated by script. TargetJoint2D does not work anymore? I tried both via script both via editor. Indeed, dragging an object, I attach by script a TargetJoint2D component and, when the touch position is updated, I use this code. It worked in 5.3.3: touchedObject.GetComponent<TargetJoint2D>().target = myTouch.position; Now the object completely freezes and does not move until I release the finger. The same happens when an object is directly instantiated with a TargetJoint2D component from the editor: it looks like it does not try to reach the target, rather it starts oscillating as if it was trapped inside a cage. Does anyone know if something has changed in the TargetJoint2D configuration and usage, or is it to be considered a new bug? Thank you.
I just tried it in 5.3.4f1 and it seems to works fine. I create a new scene, added a new GameObject with a Rigidbody2D and a TargetJoint2D and a new script that does the following: Code (CSharp): using UnityEngine; public class SetTarget : MonoBehaviour { void FixedUpdate () { var worldPos = Camera.main.ScreenToWorldPoint (Input.mousePosition); GetComponent<TargetJoint2D> ().target = worldPos; } }
Adding the TargetJoint2D dynamically also works exactly the same: Code (CSharp): using UnityEngine; public class SetTarget : MonoBehaviour { void OnEnable () { if (GetComponent<TargetJoint2D> () == null) gameObject.AddComponent<TargetJoint2D> (); } // Update is called once per frame void FixedUpdate () { var worldPos = Camera.main.ScreenToWorldPoint (Input.mousePosition); GetComponent<TargetJoint2D> ().target = worldPos; } }
This is weird.... it started working after I moved the code from Update() to FixedUpdate(). .... so sorry, and thanks: very precise and clean as usual.
You're welcome. It should still work however when used from 'Update'. It's just that nothing will move until the next 'FixedUpdate' and performing multiple moves in 'Update' is wasteful as only the last one before the next physics update will be used.