Hello. I am a Babylon.js noob
and i have been stuck on this problem for quite some time now. Im trying to implement that my character rotates toward the point where my mouse cursor is. I haven't found something like this for Babylon, but i have been trying to copy some of the unity scripts, but was unsucessful.
I have a 3D ortographic view (camera), and have been trying to do it as it is shown in the code below (something similar works in unity).
document.onmousemove = function(e){
cursorX = e.pageX;
cursorY = e.pageY;
var vector = new BABYLON.Ray.CreateNew(character.position.x,character.position.z,cursorX,cursorY,camera.getWorldMatrix(),camera.getViewMatrix(),camera.getProjectionMatrix());
character.lookAt(vektor.direction);
}
My character only rotates at the start for a small value (also in the wrong direction, i only want to rotate the x and y axis) and after that the mouse movement doesn't impact him. If anybody has any kind of tip or a solution to the problem, I would be very grateful. Cheers ![]()