Simulate WorldPosition from a LocalPosition

Hi, I need some help to simulate the worldPosition from a localPosition. Let me explain.
I have the following structure of a given gameobject:

myGameObject
- pivot

The code below works beautifully using a pivot:

pivot.localPosition = position;
pivot.localRotation = rotation;
myTransform.SetPositionAndRotation(pivot.position, pivot.rotation);

But as shown, it relies on a pivot attached to the gameobject, which I don’t like.
How can I achieve the same without a pivot?
I already tried TransformPoint/InverseTransformPoint but never managed to get the same results.

I appreciate any help on this
Regards

That’s not really enough information to help you. TransformPoint/InverseTransformPoint are the way to change between local and global coordinates, so if those didn’t work, either you used them wrong (in code you haven’t shown), or the surrounding code (that you also haven’t shown) is relying on them being local in some other way. Either way, you haven’t shown the code with the actual problem.

Hi, thanks for replying.
There’s no problem here at all. My code works fine using a pivot, but I just want to optimise it and get rid of the extra gameobject, and learn another technique as well. My question is how I can transform the code I shown to an equivalent using TransformPoint/InverseTransformPoint. Maybe it can also be useful to other developers reading this to know both techniques.

As far as I know there’s no way in unity to change the pivot point of rotation apart from:

  • Use a separate pivot object, as you are doing
  • Change the origin point of your 3d model in 3d modeling software such as blender
  • Change the pivot of your 2D Sprite in the Sprite import settings.

No worries, I’ll stick with using a pivot for now. Thanks

Have you tried this function?
https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html