# correct camera rotation when walk around of sphere

## Recommended Posts

how can correct camera  rotation when walk around of sphere

##### Share on other sites

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.

##### Share on other sites

Sorry, what I just said is stupid : a FreeCamera always looks towards the direction of moving.

I suppose that you want to position the camera permanently on the sphere instead ...

##### Share on other sites

if it's a perfect round sphere i suppose you could rotate the sphere instead, that should give the wanted result.

##### Share on other sites

we cant rotate world we have other planets too  and all planets is moving

usually i try hard way to find a solution i am work on

##### Share on other sites

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?

##### Share on other sites

ok

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

##### Share on other sites

thanks @jerome i check it and share result

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

##### Share on other sites

• 2 weeks later...

Out of curiousity, did you manage to make this work?

who? when? what?

##### Share on other sites

Well. The question was actually directed at you, sir

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.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.