[SOLVED] Changing rotation from an entity doesn't happen until it's not moving

I would like to clamp the rotation to avoid the plane to go upside-down, to do so i just clamped the rotation from the entity like this.

Clampz.prototype.clampRotation = function(){
    var planeRotation = this.entity.getRotation().getEulerAngles();
    if (planeRotation.z !== lastRotValue) {
        var clampZRotation = pc.math.clamp(planeRotation.z, -50, 50);
        this.entity.setEulerAngles(0, 0, clampZRotation);

After the plane goes static, the rotation happens. Feels weird, like the code is happening after the physics.


I’ve implemented a console.log where you can see when the rotation happens.


Extra “Thanks” to whoever knows why the image is blurry when the asset is clearly fine

As it’s a physics object, you need to do set rotations and positions via the rigidbody and not the entity as at the end of the physics simulation update, the entity is synced to the rigid body in the simulation.

If you look at the rigid body component source, you can work out how to get and set the rotation of the physics transform: https://github.com/playcanvas/engine/blob/master/src/framework/components/rigid-body/component.js#L545

The image is blurry because I’m guessing the original image wasn’t 128 x 32 pixels so when you imported it to the project, the editor resizes it to the nearest power of 2 and does a interpolation of pixel colour. Make sure your textures are powers of 2 to begin with and that should help.

Will’s Flappy Bird project is an example of using a sprite texture atlas and material UV settings to create sprites.



Damn right :smiley:
thank you!

Pd: i will work onto that sprites then, thank you again :slight_smile: