Rotate around a given point?

Is there any method for rotating an entity around a given point? Or is there a way to set the pivot point of an object?

Imagine this scenario:
I have created a flagpole (just a stretched cube) lying on the ground. Now I want to raise half-way by rotating it 45 degrees around it’s end point. I haven’t found any rotateAround() function, so instead I am trying this:

flagpole.setLocalScale(10, 1, 1); // to make my cube flagpolish
flagpole.translate(5, 0, 0); // move it so that its end point is at world’s origin
flagpole.rotate(0, 0, 45); // rotate it around world z by 45 degrees
flagpole.translate(-5, 0, 0); // move it back

However, I still end up with a flag pole half sunken under ground. I guess it’s because ‘rotate’ does not rotate around the world’s origin. So… I guess I have to go via matrixes to achieve what I want, but isn’t there an easier way? It seems like rotateAround() is an obvious missing nice-to-have-piece.

I’m not sure if this is the best way, but you can create a parent entity at (0, 0, 0) which works as an axis. Then you rotate the parent instead of the flagpole and it should give you the right results. I drew a diagram but I’m replying from my phone so apologies for the quality.

1 Like

if u want to rotate the flag use this rotate.js as script in the flag object
pc.script.create(‘rotate’, function (app) {
var Turn = function (entity) {
this.entity = entity;

Turn.prototype = {
    update: function (dt) {
        this.entity.rotate(0, dt * 90, 0);

return Turn;