Plonq / bevy_rts_camera

RTS-style camera controls plugin for Bevy Engine
Apache License 2.0
53 stars 5 forks source link

Add ability to lock mouse cursor on rotate/grab pan #13

Closed juliohq closed 4 months ago

juliohq commented 4 months ago

This PR introduces two new variables: lock_on_rotate and lock_on_drag. They are meant to allow the mouse cursor to stay in place while rotating/dragging. The cursor is hidden when performing such actions (so CursorGrabMode::Locked works fine on Windows and Linux).

I've set the default to false for both lock_on_rotate and lock_on_drag variables and true. Do you think they should be enabled by default?

Plonq commented 4 months ago

This actually doesn't work. Perhaps your cursor locking is messing with MouseMotion events.

https://github.com/Plonq/bevy_rts_camera/assets/7709415/0febf242-d3f1-4a7c-b60f-73884a7690df

juliohq commented 4 months ago

This actually doesn't work. Perhaps your cursor locking is messing with MouseMotion events.

Screen.Recording.2024-04-29.at.19.55.06.mov

That's the intended behavior, the mouse cursor stays in place.

Plonq commented 4 months ago

This actually doesn't work. Perhaps your cursor locking is messing with MouseMotion events.

Screen.Recording.2024-04-29.at.19.55.06.mov

That's the intended behavior, the mouse cursor stays in place.

If you watch the video, you can see the camera actually barely moves, but I'm trying to move it. It's stuck, can't rotate it and can't drag it.

Maybe this is OS dependent.

Plonq commented 4 months ago

Note: what I suspect is happening is that manually moving the cursor back to where it started actually triggers MouseMotion events, thus also moving the camera back to where it started. If that's the case, you'll have to find an alternative solution.

juliohq commented 4 months ago

I think we can use bevy's built-in CursorGrabMode::Locked mode until https://github.com/rust-windowing/winit/issues/3094 is solved. As pointed here, the issue is invisible if you just hide the cursor on Windows and Linux, so as long as the locked mode works fine on macOS I think we're fine.

Plonq commented 4 months ago

I think we can use bevy's built-in CursorGrabMode::Locked mode until rust-windowing/winit#3094 is solved. As pointed here, the issue is invisible if you just hide the cursor on Windows and Linux, so as long as the locked mode works fine on macOS I think we're fine.

Sounds good to me

juliohq commented 4 months ago

@Plonq is there anything missing for this PR to be merged?

Plonq commented 4 months ago

Apologies! I didn't realise you'd already made that change.