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

Support for AtmosphereCamera in child position #40

Closed
mbrc12 opened this issue Jan 2, 2023 · 3 comments
Closed

Support for AtmosphereCamera in child position #40

mbrc12 opened this issue Jan 2, 2023 · 3 comments

Comments

@mbrc12
Copy link

mbrc12 commented Jan 2, 2023

The following modification of examples/basic.rs seems to not work for me:

use bevy::prelude::*;
use bevy_atmosphere::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(AtmospherePlugin)
        .add_startup_system(setup)
        .run();
}

#[derive(Component)]
struct Player;

fn setup(mut commands: Commands) {
    commands.spawn(Player)
        .with_children(|p| {
            p.spawn((Camera3dBundle::default(), AtmosphereCamera::default()));
        });
}

Is it not supported to have AtmosphereCamera as a child? Having the Camera as a child is often useful because it inherits the transforms of the parent Player. I am open to suggestions on how to better structure this if not supporting this is intentional.

@JonahPlusPlus
Copy link
Owner

JonahPlusPlus commented Jan 2, 2023

Bevy gives you a couple warnings:

2023-01-02T19:09:10.061343Z  WARN bevy_hierarchy::valid_parent_check_plugin: warning[B0004]: An entity with the GlobalTransform component has a parent without GlobalTransform.
This will cause inconsistent behaviors! See https://bevyengine.org/learn/errors/#B0004
2023-01-02T19:09:10.061346Z  WARN bevy_hierarchy::valid_parent_check_plugin: warning[B0004]: An entity with the ComputedVisibility component has a parent without ComputedVisibility.
This will cause inconsistent behaviors! See https://bevyengine.org/learn/errors/#B0004

To see the atmosphere, you just need to add a VisibilityBundle to your parent.

If you are going to move your player around, you also want a TransformBundle.

Instead of adding both these bundles, you can just add a SpatialBundle:

use bevy::prelude::*;
use bevy_atmosphere::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(AtmospherePlugin)
        .add_startup_system(setup)
        .run();
}

#[derive(Component)]
struct Player;

fn setup(mut commands: Commands) {
    commands.spawn(Player) 
	.insert(SpatialBundle::default()) // or just `spawn((Player, SpatialBundle::default()))`
        .with_children(|p| {
            p.spawn((Camera3dBundle::default(), AtmosphereCamera::default()));
        });
}

@mbrc12
Copy link
Author

mbrc12 commented Jan 2, 2023

I see, thanks for pointing that out! Surprisingly, bevy does not show that warning in --release mode, which is what I was using, but does show it in debug mode.

@JonahPlusPlus
Copy link
Owner

Ah, interesting. I've never noticed that. I recommend reading more about Bevy's visiblity system. You're not the first person to be tripped up by it (I should make it part of an FAQ).

@JonahPlusPlus JonahPlusPlus mentioned this issue Jan 2, 2023
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants