Jump to content

Rotate mesh on drag to mimic arcRotateCamera

Bob Razowsky

Recommended Posts

Hi all!

I searched the forum but did not find an aswer.

I'd like to rotate a mesh on drag. It would look pretty much like if I was using and ArcRotateCamera, but I need a fixed camera.

As anyone tried something like that yet? Another option would be to attach my background to the camera and copy the rotations, making it look like the background is fixed,  but I can't make it work.

Any ideas would be amazing!

Thx a lot!

Link to comment
Share on other sites



You can try that : http://babylonjs-playground.com/#1QPOEL

Look closer at : 

 var onPointerMove = function (evt) {
        if (!startingPoint) {

        var current = getGroundPosition(evt);

        if (!current) {

        var diff = current.subtract(startingPoint);
       // currentMesh.position.addInPlace(diff);
	// new line added
		currentMesh.rotation.y += diff.x/20;
        startingPoint = current;



Link to comment
Share on other sites

Hi Samuel, thx for your answer!

I tried something similar, using mstate instead of pickInfo, and using mesh.rotate() to allow rotations on local axis. It kinda works! 

var diffX = mstate.x - this.startX;
var diffY = mstate.y - this.startY;

this.engine.skate.rotate(BABYLON.Axis.Y, -diffX / 20, BABYLON.Space.LOCAL)
this.engine.skate.rotate(BABYLON.Axis.Z, diffY / 20, BABYLON.Space.LOCAL)

I'll try to add some inertia now! 

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...