South pole camera flippage

Hello,

I’ve been trying to put together a bare-bones planet hopping simulation. I’m definitely not up to date on best practices and am very open to all kinds of nitpicks/optimizations/suggestions. The short-term goal is just to add more planets and be able to move from one to another.

Playground link
controls: WASD, spacebar, V, shift, C, F, escape, F1

The issue I’m currently trying to deal with seems to about rotation (what a surprise), specifically messing with the cameras’ up vectors and going all the way upside down. Getting too close to the south pole makes the ArcRotateCamera’s keyboard controls misbehave (as well as suddenly change its own position) and the UniversalCamera flip up/down and left/right on the mouse.

The up vector is at 124, the forward and left vectors and camera are from 145 to 152, and the keyboard controls start at 229. Any help would be greatly appreciated.

There is a setting on ArcRotateCamera which turns of the zoom to far behavior.

camera.allowUpsideDown = false

Does that help?

1 Like

No, changing allowUpsideDown doesn’t affect anything here as far as I can tell

Hello and welcome to the Babylon community! @PolygonalSun our camera expert might have some tips on how to deal with inversing the up vector

2 Likes

Hey, so I’m currently taking a look at the PG to see what’s going on. It looks like when I get to the south pole, it’s hopping back and forth around it. When I have more of an idea of what’s going on, I’ll let you know.

2 Likes

Sorry about the delay on this. I’ve been thinking about this one a bit and I believe that a way to avoid any issues with the poles might be by doing something like making the cameras children of the player. You should be able to get the upVector by using the position of the closest planet and the position of the player (this.body.subtract(somePlanetMesh.position).normalize(), I think). You might need to do a bit of translation for the cameras from local space to world space (getAbsolutePosition()) I think that might work.

3 Likes

Hi again,

I haven’t been able to spend much time on programming lately but I recently fiddled around trying to fix this bug without much success. I’ve noticed that there are upVector functions for the cameras but nothing similar that I can find for a left/right vector and I’m curious if there’s some way I might be able to see or modify that property?

You can get the forward direction in getForwardRay, and derive the X axis direction from there :slight_smile:

1 Like

There does definitely seem to be a mismatch with what scene.player.forward returns and with what either camera’s getForwardRay returns, but mostly with the y values. I had a look at babylon.max.js and I was able to find a rightAxis in the BoneLookController function, so I have a feeling that I’m using left in my code when I’m supposed to be using right or I have to switch them at some point on the way to the south pole?