Sign in to follow this  
Detox

Rotation with FreeCamera

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.