Following object (arrow) slides off of a object
Hello, I'm beginner with Unity, so maybe this is pretty basic.. but I couldn't find any help.. So I'm creating a model of Solar System and now when I wanted to add an arrow pointing to a GameObject I just made it a child of the object (moon). I expected to just normally follow the object, which it does, but instead of remaining upward, it "slides", as you can see on pictures. The arrow doesnt have a rigidbody and any script attached.. Is here some way how to make the arrow upward? I really don't seem to get what is wrong so thank you very much for any help :]
Answer by ExamplesAreExamples · Nov 25, 2015 at 12:45 AM
Well something is rotating it by the looks of it. Perhaps the parent object rotates (the moon).
You could unparent it and add a script that copies transform.position from the selected object (during LateUpdate for example).
public class CelestialBodyArrow : MonoBehaviour
{
public Transform celestialBody;
void LateUpdate()
{
transform.position = celestialBody.position;
}
}
If the arrow becomes buried in the planet, move the script to an empty game object and put your arrow as a child of the empty game object. Offset your arrow game object relative to your new root object so it makes sense. You can also ask the celestial body how large it is, so the arrow can scale and position itself appropriately to work with any sized celestial.
In this case, create a CelestialBody script, change the type of celestialBody to CelestialBody (from Transform), and expose a member (method, property or field) that can provide you with the information you need.