I’m currently developing an engine for a new game I’m making. In it, the player will be able to use the arrow keys or WASD to change the direction of the gravity as desired. I also want the avatar to rotate to be standing “upright” according to the direction of the gravity. For this I was going to use Tween and use the SineInOut method to make a nice, fluid animation. Here’s an example of what the code looks like (this is inside of the script update function) for one of the arrow keys (I won’t bother showing all of them; they’re all the same except for the direction of the gravity and rotations):
if (this.app.keyboard.wasPressed(pc.KEY_LEFT) | this.app.keyboard.wasPressed(pc.KEY_A)) {
//change the gravity
this.app.systems.rigidbody.setGravity(-50, 0, 0);
//rotate the avatar using tween
this.entity
.tween(this.entity.getLocalRotation())
.to(new pc.Vec3(0, 0, -90), 0.5, pc.SineInOut)
.loop(false)
.yoyo(false)
.start();
return;
}
However, when hitting any of the arrow keys or WASD keys, the avatar immediately zooms towards the camera (or at least seems to), although it does visibly rotate if you look closely. The exception is when you hit Down or S, which fixes it, but I’m pretty sure it does this since the rotation is set back to the original rotation. I further attempted to debug this by created a perspective camera. Even when I zoomed out all the way to 999z, the avatar still covered the screen. Also keep in mind that the linear factor for the parent entity of the sprite, which is the one which is simulated by the physics (I did this so that the camera wouldn’t rotate with the avatar) is set to 0 for Z. So it SHOULD NOT zoom towards the camera like that.
Any help is greatly appreciated. Here’s the link to my editor. The code can be found in Controller.js which is inside of the Scripts folder.