Reset model orientation

Hi, ianMac here!

I’m new to this. So far it’s going good but now have a question: how do you reset the orientation of a model? I am trying to spin a cube on each of its 3 local axes. One works as expected, the other 2 spin but the axes isn’t aligned correctly to the object.

Thanks.

Hi ianMac!

There are a couple of functions you’ll be interested in for this:

http://developer.playcanvas.com/engine/api/stable/symbols/pc.fw.Entity.html#setEulerAngles
http://developer.playcanvas.com/engine/api/stable/symbols/pc.fw.Entity.html#setLocalEulerAngles

So let’s say you want to set an entity’s orientation to be aligned with the world’s XYZ axes. You would have to do:

this.entity.setEulerAngles(0, 0, 0);

Or if you wanted to have the same orientation as the parent of the entity, you would do:

this.entity.setLocalEulerAngles(0, 0, 0);

Or let’s say you want to reset an entity to have the orientation it had on initialize, if it has since been rotated away somehow. You would do:

initialize: function () {
    this.startRotation = this.entity.getRotation().clone();
}

reset: function () {
    this.entity.setRotation(this.startRotation);
}

Note here that we are using get/setRotation instead of get/setEulerAngles. You can actually use either. get/setRotation use quaternions rather than Euler angles and are a bit more reliable and quicker to work with.

Thanks. Problem solved.

I am trying to do a similar project. But I do not know what I’m doing wrong. It does not work yet. :frowning: Any update help that you can share with me will be very useful for me … Thanks this is the protecto with the help of @yaustar. https://playcanvas.com/project/525013/overview/by-yaustar