Camera rotation and mouse direction

Hi,

Updated PG (it was definitely not showing the issue properly)
https://playground.babylonjs.com/#Y6Z81M#3
Please try the mouse move with the camera.rotation.z = 1.57; uncommented. You will experience what I am talking about.

The issue with the pointerlock is that when the camera rotates around an axis, the mouse mouvement becomes inconsistent (you sometimes have to invert your mouse move to get the right movement).

Is there a solution to automatically handle this, so that no matter the camera rotation, moving the mouse to the right make the camera tilt to the right?

What I want approaches this
https://doc.babylonjs.com/guidedLearning/workshop/Track, but without the track for this very animation.

To better visualize: imagine you are in space, near an orbital station, and an event happens, you are upside down.

At this moment, the issue is that the mouse moves are inverted. To me it is important to keep the camera moving in local space as it is easier to reason about.

thanks!

Not sure if this is what you looking for, but what I used to link mouse move and camera rotation is this PG:

2 Likes

Ah, perfect exemple:

see what happens when you up the mouse so much that your “head” should be upside down? mouse control is inverted.

I am pretty sure it must be handled in an eventlistener depending on the current camera rotation: the idea would be “past that rotation, handle mousemove that way”.

Maybe an option exists already though…

I guess you could invert the values past this point. Not sure why you would do this.
Are you in a space environment where you can be upside down? I mean, even in a plane flying on the back you would keep with the same direction, only the inputs are inverted. Or is it for a drone that always has facing input or something (just curious :thinking:)?
Anyways, I guess you can limit it with a runtime.

So I guess you can also invert the values past the point.

Hi Mawa,
It is actually a scene in which you are in space and you must operate on the station. At times, you end up with the camera inverted and keep the operation going.
But the direction is not always completely inverted, depending on the slope of the spaceship. That’s why it’s complicated.

I thought about inverting the rest of the world but it has thin instances, meshes, instances, and lot of them. That would break a lot of optimization.

That’s why I feel stuck. :thinking:

I see. The only problem I see here is that if you straight invert the values for the mouse input when upside down, it will cause a weird feeling and particularly when on the edge. I wonder if you should not rotate Math.PI on the horizontal axis when you pass the inverted point, and do it with an offset/deadzone and a slow animation (as if the character/astronaut would rotate to put himself in the upright position relative to the object). I guess this would feel more natural and would make more sense then simply inverting the inputs? My opinion only. I suppose only a test will tell.

Edit: I just did read your post again and I think what you are refering to is ‘leaning’. I’m just wondering how you can turn and lean with a natural feeling simply with the mouse. May be you should assign keys to lean?

3 Likes

When reading the source of this pg it appears that doing what I want (but here in a non controllable way) will implie multiple matrix calculations and may break at times.

Like you said, maybe I should do an animation and disable the mouse while not repositioned… hmmmm…

Hmmmmmmmm… time for some tests! I will report what solution I chose after moving mountains :upside_down_face:

Here’s a quick non-academic test for you, using A and D keys for leaning. F to reset (no leaning).
It’s just for testing. It would need to be worked with an ease and may be increase speed while holding key. I still think you cannot use just the mouse that moves only on X and Y to simulate XYZ behavior. It will be uncontrolable (in my opinion).

2 Likes

So, mawa, I will follow your recommendation

mawa:
and a slow animation (as if the character/astronaut would rotate to put himself in the upright position relative to the object)

That is exactly it: the animation will occur with mouse cursor off, and reactivate it once the rotation is complete. I will put the camera on a track and target an empty, to make sure that everything is handled properly…

That is at least solving the move issue without taking back the animation I want. I will rethink the operations accordingly.

:pray: :pray: :ok_hand: :blush:

1 Like

I would be interested in seeing the result. If you can notify me once you are happy with the result.
Meanwhile, have a great day :sunglasses:

Once the game is in a proper state, you will know for sure :blush:

2 Likes