Rotate entity around given world point

Hi guys,

I wonder how to rotate given entity around custom world point (not around its origin)? AFAIK there is no specific engine function/method that solves this problem. Does anyone have some code snippet for this?
I know it’s possible using pc.Mat4, but don’t know any details of how that could be done.

This isn’t so simple to do with a single entity in code, but you can use another trick:

  1. Create a single entity at the world point
  2. Add a child entity and move it to the desired distance from the world point
  3. Rotate the parent entity
2 Likes

I would have thought you could use the pc.Mat4.transformPoint method. Set the rotation values and worldpoint in the matrix and transform the local offset position (probably along -Z)

2 Likes

I think this is the easiest way to achieve what you want.

Also, the way the orbit-camera works is exactly like that: rotating around a target pivot. Maybe you can check on that code to help you.

You could create a parent entity and add other entities as it’s child. Then rotate the parent entity.