Jump to content

correct camera rotation when walk around of sphere


Recommended Posts

I think that a FreeCamera, when moving, has a cameraDirection property what a Vector3 oriented in the way the camera moves.

So if you add camera.position and camera.cameraDirection, you'll get a result that could be used as camera target. Thus you will look in the way you walk.

Link to comment
Share on other sites

@jerome thanks for reply maybe i ask wrong question

i correct camera position now

and i have gravity for any planet 

i think i need re calculate " camera target position "

my next question : any way to define a jump or automatic  walk for camera with collision and gravity?

Link to comment
Share on other sites


just an idea (pseudo code, all these following are vector3 substraction or addition or cross product) :

var axisCam = camera.position - sphere.position;  // axis cam-sphere center, so a sphere radius vector 

var axisMove = CopyFrom(camera.cameraDirection);              // axis of the cam movement, copy the last defined value. You could get Axis.X before it's defined (before the first camera move) to give an initial view direction, or any direction that you would choose by default. Just don't set it to zero.

var cross1 = Cross(axisCam, axisMove);              // a first orthogonal vector to the radius and the movement, so cross1 if tangent to the sphere

var cross2 = Cross(axisCam, cross1);                   // this one is orthogonal to the radius, tangent to the sphere and colinear to the movement... if not right try instead Cross(cross1, axisCam)

var target = camera.position + cross2;


this should work

Link to comment
Share on other sites

Ain't it great when Jerome talks Math-smack like that?  Friggin' Orthogonoids... ya gotta love 'em!

Jerome, of course, taking a professor-like approach, where as I... would hack lookAt().  :)  (ie. Make the bottom of the camera constantly lookAt the planet core.)

Link to comment
Share on other sites

  • 2 weeks later...

Well. The question was actually directed at you, sir :P

Were you able to somehow reset the camera rotation/translation when getting to the other side of the sphere?

I simplyfied your example a bit, just to make it easier for myself: http://www.babylonjs-playground.com/#RW25F#7

I'm not even sure that I understand the issue, really. Is it something like the below demonstration?:


I'm leaning mostly toward the first figure, as you quickly get the issue of the camera limitation/boundary downward/Y axis. As well as the camera just being 'off'.

This has the potential to make some fun "border-less" game maps, if you adjust the camera accordingly, or make big enough spheres.


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