Jump to content

Rotation with FreeCamera


Detox
 Share

Recommended Posts

Hello!

First of all: I'm new to Babylon.js  :) and looked through the Babylon.JS-Tutorials on Github.

 

But now I'm stuck and don't know why: I looked at the 18 - Drag and Drop Example and instead of moving the Meshes I tried to simply rotate them, that worked fine. But when I change the BABYLON.ArcRotateCamera to  BABYLON.FreeCamera it wouldn't rotate the objects in the front anymore, only the one in the back?!

 

On my search for a Solution I found this Thread, where somebody posted this Example  (A Modification of the Drag And Drop - Example), there I also replaced the BABYLON.ArcRotateCamera with a BABYLON.FreeCamera.

 

Heres my Modification with the FreeCamera: Playground/#2CEF73

 

Now if I replace this 5th line of code

var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(10, 10, 10), scene);	

with this:

var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(10, 10, -10), scene);	

it works.

 

But why??? How can I modify the code to make it work with the first line of code?

Link to comment
Share on other sites

Hi and welcome!

So. A few things about your implementation :-)

  1. scene.pick gets requires 2 parameters (in your case). pointer X and pointerY. There is no pointerZ in the scene, as this refers to the mouse 2D coordinates on the screen.
  2. Same thing goes to createPickingRay . 
  3. You have provided both with pointerZ (which doesn't exist). But this is not the cause to your problem :-)
  4. The main cause is the camera's target. 
    camera.setTarget(greenBox.position);

    after creating the greenBox solves this issue. I didn't debug it completely, but this is what's missing and this will make it work with any of the positions.

Updated demo - http://playground.babylonjs.com/#2CEF73#2

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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