This is my camera code:
use crate::{player::Player, world::MyMainWorld};
use bevy::prelude::*;
use bevy_voxel_world::prelude::*;
const CAMERA_DISTANCE: f32 = 1.0;
const HORIZONTAL_ANGLE: f32 = 45.0_f32.to_radians();
const VERTICAL_ANGLE: f32 = 35.0_f32.to_radians();
pub fn spawn_isometric_camera(
mut commands: Commands,
player_query: Query<&Transform, With<Player>>,
) {
let player_position = player_query.single().unwrap().translation;
let offset_x = CAMERA_DISTANCE * HORIZONTAL_ANGLE.cos() * VERTICAL_ANGLE.cos();
let offset_y = CAMERA_DISTANCE * VERTICAL_ANGLE.sin();
let offset_z = CAMERA_DISTANCE * HORIZONTAL_ANGLE.sin() * VERTICAL_ANGLE.cos();
let camera_position = player_position + Vec3::new(offset_x, offset_y, offset_z);
// Create transform looking at the player
let transform =
Transform::from_translation(camera_position).looking_at(player_position, Vec3::Y);
commands.spawn((
Camera3d::default(),
Projection::Orthographic(OrthographicProjection {
scale: 0.05, // zoom level
near: -35.0, // Increase this (more negative = see more behind)
far: 50.0,
..OrthographicProjection::default_3d()
}),
transform,
VoxelWorldCamera::<MyMainWorld>::default(),
));
}
pub fn move_camera_towards_player(
player_query: Query<&Transform, With<Player>>,
mut camera_query: Query<&mut Transform, (With<Camera3d>, Without<Player>)>,
) {
let player_position = player_query.single().unwrap().translation;
let mut camera = camera_query.single_mut().unwrap();
camera.translation.x = player_position.x;
camera.translation.z = player_position.z;
}
``` In my mind, this should not work, this should position the camera on top of my player (on the first movement key stroke) and face forward, I should not be able to see my player, but I see it. Does the Transform thing changes the camera anchor point or something like that?