Plonq / bevy_rts_camera

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

Focus not on the ground? #6

Closed tad-lispy closed 6 months ago

tad-lispy commented 6 months ago

Hi again! I'm trying to implement custom controls for my camera and for that I need to know where the camera is pointing at on the ground. My understanding was that the focus or target_focus contain this information, but when reading those properties I'm getting a point high above the ground (large y coordinate), even if I manually set the target focus to be at y = 0.0. It also changes when zoom is changed. I think it basically contains the current camera height. Is this intentional? Could you please advise how to get the coordinates on the ground?

My naive way of doing that is as follows, but it doesn't account for any ground topology.

let ground_focus = camera.focus.translation.xz().extend(0.0).xzy();
Plonq commented 6 months ago

Hi! You're correct that the target_focus is automatically adjusted and reflect the camera's height. I'll need to think about this a bit more but a hacky way to get the actual focal point is to reverse engineer it by subtracting cam.height_max.lerp(cam.height_min, cam.target_zoom) from the Y coordinate of focus or target_focus. (That's the value added to the ground surface in order to follow the ground.)

EDIT: use zoom in that lerp if using focus

Plonq commented 6 months ago

I have pushed 0.4.2 which contains https://github.com/Plonq/bevy_rts_camera/pull/8. focus now isn't moved up to the camera's height and you can use it directly instead of subtracting the height from it.