Rotation seems static? Bug? or Misunderstanding of it's use?

So a few things I’m not sure about with the ‘this.entity.rotate’ function.

It seems static based on this code I did, and what I mean by static is that it’s rotating my object but not updating the ‘this.entity.foward’ instead just reseting to the original forward direction the scene starts in.

var ForwardAndRotation = pc.createScript('forwardAndRotation');

ForwardAndRotation.prototype.initialize = function() {
    this.moveSpeed = 5;

ForwardAndRotation.prototype.update = function(dt) {
    var forward = this.entity.forward;

If I were to rotate the object in the editor it would update in the object’s forward direction no problem. It’s only when I use the ‘this.entity.rotate’ function where it doesn’t care at all. Same with setting the rotation or euler angles. The only thing I found that works for turning the object in scene is ‘applyTorque’ but I just don’t understand why this is happening.

Another weird thing is that the rotation code I wrote takes like 1 second to actually begin rotating which is also weird.

Just curious if you guys had information on all these issues since I’d like to understand what is going on. Again using Torque seems to be the right solution to rotate the object the way I want (with updating it’s foward vector) but it just seems more intuitive to use the rotate functions so yea some light on this would be helpful.

Here is a link to my project >>

If it’s a rigid body, you need to rotate it by using angular velocity or torque (which is another ‘force’). If you want an immediate response, use change angular velocity or use torqueImpulse (pplyTorqueImpulse). Adding torque every frame is like applying acceleration. It gradually speeds up the longer you apply it.

It’s like moving a rigid body with entity.setPosition. It won’t work as the rigid body is setting the position and rotation of the entity every frame.

1 Like


“the rigid body is setting the position and rotation of the entity every frame”

That’s the answer I was looking for. I had a feeling this was the case since I did the suggestion you made about torque (Haven’t tried angular velocity)

The thing I’m still confused is that if I change the rotation in the editor it changes the rotation. So does this mean that the editor updates the rigid body’s rotation using a separate measurement?

This is fine, I just want to know for my own deeper understanding and mastery of PC. Thanks again Yaustar as always ;D

Are you talking about when the game is running on another tab or just in general?

Yea like the game is running and I adjust it in the editor.

I think that’s ‘special’ messages sent to the game from the editor. It’s probably moving the entity and calling syncToEntity on the rigid body (which you shouldn’t generally do all the time as it basically resets the state of the rigid body).

1 Like