Hi, I have an object that I want to stay at the top of my character. I don’t want to parent it but I do want it to be there. I tried
Public transform target
transform.position = new Vector3 (target.transform.position.x, target.transform.position.y + 4, target.transform.position.z);
But that didn’t work. How is this possible?
Where was this code located?
Put that second line inside an Update function, and assuming ‘target’ is the object you want to follow, Bob’s your uncle.
I think you could do like…create a isolated script for the the object to stay on top of your head or you could work in the charactet script, which would be:
public GameObject hat; //In inspector associate the GameObject
void FixedUpdate()
{
if(hat)
hat.transform.position = new Vector3(transform.position.x, transform.position.y + 4f, transform.position.z)
}
We would use FixedUpdate() in this case because it’s recommended if you want to work with positions, rotations, etc.