I’m quite frustrated right now. I’m simply trying to make an object move forward, but it’s always moved on the global z instead of local z axis.
gameObject.Find(chainLink.name).transform.localPosition.z += 1*linkNum;
I’m quite frustrated right now. I’m simply trying to make an object move forward, but it’s always moved on the global z instead of local z axis.
gameObject.Find(chainLink.name).transform.localPosition.z += 1*linkNum;
Is that object the child of something? localPosition is relative to the parent, so localPosition.z is the parent’s z axis.
–Eric
You might want to use Transform.Translate then.
Yes, it’s a child of an object. I’ve tried localPosition and position, but they do the same thing - always move the object in the same direction. It doesn’t make a difference if the object is a child or not.
Oh, I forgot about that! That actually worked. Thank you.
If adding to .localPosition and .position do the same thing for a child object, that means the parent object is aligned with the world axis. localPosition works as expected and isn’t ignored. It’s not the object’s orientation that’s used, it’s the parent’s, that’s why it’s local. If you want the object to move relative to its own orientation, then it’s easiest to use Translate as niosop said.
–Eric
It would actually move the same no matter the rotation of the parent. Translate did the trick. Thanks for your help.