Jump to content

Rotating Mesh Around Y Axis using lookAt


Recommended Posts

Is lookAt the best function  for rotating the mesh around the Y access based on the location of the mouse pointer?

My code currently looks something like this:

let rotateMesh = function(evt) {

let vec3 = new BABYLON.Vector3(0, evt.clientX, 0);



The problem is that it throws the mesh out of position. How would I rotate it around only the Y position, while keeping the X and Z coordinates the same? If using the lookAt function is not the best approach, what would be a better approach?

Link to comment
Share on other sites

I don't know enough about Babylon to help with that yet, but I've refactored your event handling code to remove a bug: you never cancel the onMouseMove once the object hit is confirmed.

This will hopefully be a bit easier to work with:


The console shows that the onMouseMove code only runs when the button is down.

Link to comment
Share on other sites

        engine.runRenderLoop(function () {

You do not need this code within a playground as the playground wrapper already supplies this. See if removing it smooths the scene as you are double calling.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...