Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background Parallax #96

Closed
thombruce opened this issue Nov 13, 2023 · 2 comments · Fixed by #117
Closed

Background Parallax #96

thombruce opened this issue Nov 13, 2023 · 2 comments · Fixed by #117
Labels
core New feature or request
Milestone

Comments

@thombruce
Copy link
Owner

Related: Issue #85 + PR #95

As part of an effort to upgrade to Bevy 0.12, I have removed bevy_tiling_background which was previously responsible for...

  1. The tiling background (this is now reimplemented directly using only native Bevy utilities)
  2. A sort of parallax effect between this tiling background and foreground elements

This parallax effect is now absent, and we should seek to reimplement it... somehow.

@thombruce thombruce added the core New feature or request label Nov 13, 2023
@thombruce thombruce added this to the v0.1.0 milestone Nov 13, 2023
@github-project-automation github-project-automation bot moved this to Inbox in Verse Nov 13, 2023
@thombruce thombruce mentioned this issue Nov 13, 2023
5 tasks
@thombruce
Copy link
Owner Author

Perhaps take a look at how .with_movement_scale() worked; this is the method used for this effect previously:

image

@thombruce
Copy link
Owner Author

Take a look at how the bevy-parallax crate achieves its horizontal parallax effect: https://github.com/Corrosive-Games/bevy-parallax/blob/main/src/lib.rs#L65

There's not much to it. The background is following the camera, moving by some scale offset by a multiplicative factor.

Now, I can't just reuse the same follow_ logic that I did to have the camera follow the player as that matches the new coordinates exactly (it has no sense of how far has been moved - it is sort of teleporting each tick to find the player) but...

If I could somehow get the distance moved by the camera/player since the last update, then I could shift the background by this amount multiplied by a scaling factor... We could use an event to communicate that information.

But do we need to get the distance change? Can't we just divide the distance from the origin by a scaling factor and this... should be good for all possible distances?

new_pos = camera_pos  * parallax_factor // where parallax_factor is in the range 0.0...1.0

A factor of 1.0 would appear to be fully static (matching the ship and camera) and a factor of 0.0 would appear to match the star and planets (the resting frame).

So consider adding a Parallax(pub f32) component and a pub fn move_parallax function that multiplies the camera position by that f32 each frame to get the new position of the parallaxed entity. The reason we wrap a pub f32 is so that we can have different layers with different parallax factors.

That works... but only for static layers. It may be a worthwhile future exercise to consider how this might be achieved for layers that contain objects in motion.

@thombruce thombruce mentioned this issue Nov 21, 2023
5 tasks
@github-project-automation github-project-automation bot moved this from Inbox to Done in Verse Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant