How can i keep the x and z axis at zero?
This is code from an example but it rotates on all axes.
game.scene.onPointerDown = function (evt, pickResult) {
if (pickResult.hit) {
let targetPoint = pickResult.pickedPoint;
player.character.lookAt(targetPoint.negate());
}
}
I’m not sure to fully understand what you want to do, but if you don’t want to change the x/z coordinates, just build a vector by getting the x/z components from player.character.position
and the y component from targetPoint
. Then pass this vector to the lookAt
function.
JFerret
November 9, 2019, 11:07pm
3
Thx for the reply!
Your solution worked with a box but not with mi character and i did not understand why.
After allot of cursing i found out that i need to use quaternion rotations because i’m rotating a physics root.
If i only knew this hours ago, i tryed every method i could find to rotate mi character.
It turned out to be easy, only two lines of code to reset the x and z axes.
game.scene.onPointerDown = function (evt, pickResult) {
if (pickResult.hit) {
player.physicsRoot.lookAt(pickResult.pickedPoint);
player.physicsRoot.rotationQuaternion.x = 0;
player.physicsRoot.rotationQuaternion.z = 0;
}
}