How can I make a GameObject attach (or "stick") to another GameObject after collision? The problem: I want the GameObject to attach after collision even if it changes scale.
What I have tried:
protected Transform stuckTo = null; protected Vector3 offset = Vector3.zero; public void LateUpdate() { if (stuckTo != null) transform.position = stuckTo.position - offset; } void OnCollisionEnter(Collision col) { rb = GetComponent<Rigidbody>(); rb.isKinematic = true; if(stuckTo == null || stuckTo != col.gameObject.transform) offset = col.gameObject.transform.position - transform.position; stuckTo = col.gameObject.transform; } This code makes a GameObject attach perfectly after collision. But when that GameObject changes scale (while it's attached), it visually no longer looks attached to whatever it collided with. Basically, this code makes the GameObject stick with only the original scale at the moment of the collision. How can I make the GameObject always stick to whatever it collided with? And with whatever scale it has during the process?