Simple script that allows an object to move with the car while on top of it but moves independent again when it falls/jumps off.
When the object enters the trigger it works as intended, however when it exits it changes location (25, 5, 8 relitive to object → 25, 5, 8 in world position) even though worldPositionStays is set to false. any ideas on how to solve the problem?
public class AttachObject : MonoBehaviour
{
public GameObject Car;
private void OnTriggerEnter(Collider other)
{
other.gameObject.transform.SetParent(Car.transform, true);
}
private void OnTriggerExit(Collider other)
{
other.gameObject.transform.SetParent(null, true);
}
}