In our new game, I am trying to rotate a wheel when the key D is pressed. Code is below.
var WheelRotation = pc.createScript('wheelRotation');
// initialize code called once per entity
WheelRotation.prototype.initialize = function() {
};
// update code called every frame
WheelRotation.prototype.update = function(dt) {
if (this.app.keyboard.isPressed(pc.KEY_D)) {
this.entity.rotateLocal(10, 0, 0);
}
};
// swap method called for script hot-reloading
// inherit your script state here
// WheelRotation.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/
As evident, the code is extremely simple. However, the wheel does not rotate perfectly - https://launch.playcanvas.com/838901?debug=true - the tyre and rim are rotating at different speeds.
I am trying to keep the Wheel Parent in the center of the ‘treckter’ model, but I am not getting the perfect center position. The rim and the tyre are separate meshes. Is there any way I could solve this issue?
I think the issue is with the pivot point that is set for both objects in Blender. That has to be the same for both objects and it has to be at the center, where the axis that both objects are supposed to rotate around in Playcanvas.
Try playing with the pivot point in Blender, re-export and check how the rotation is affected.
The tyre is not rotating at a different speed to the rim, it just looks like it because of the pattern. If you slow the speed right down, you can see that the rim and the tyre rotate at the same rate