when I'm spawning missile the tip of the Missile is pointing upwards that is to the Y axis. How do I rotate the missile so that it can point towards the asteroids. on 2D alike screen in a 3D environment.
In my game X LEFT pointed, Z is 90deg upward, and Y is towards the user screen. (missile model https://poly.pizza/m/1Xid2Qhqn2s)
Here is my missile spawn code:
fn spawn_missile(
mut commands: Commands,
scene_assets: Res<SceneAssets>,
query: Query<&Transform, With<Spaceship>>,
keyboard_input: Res<ButtonInput<KeyCode>>
) {
let transform = query.single();
let acceleration = Vec3::new(0., 0., -MISSILE_ACCELERATION);
let _transform = Transform::from_translation(transform.translation + -transform.forward() * MISSILE_FORWARD_SPAWN_OFFSET);
if keyboard_input.just_pressed(KeyCode::Space) {
commands.spawn((
MovingObjectBundle {
acceleration: Acceleration::new(acceleration),
velocity: Velocity::new(-transform.forward() * MISSILE_SPEED),
model: SceneBundle {
scene: scene_assets.missile.clone(),
transform: _transform,
..default()
}
}
));
}
}
and here is my camera:
fn spawn_camera(mut commands: Commands) {
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0., CAMERA_DISTANCE, 0.).looking_at(Vec3::ZERO, Vec3::Z),
..default()
});
}