Skip to content

Commit

Permalink
Work on fixing radar calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
dividebysandwich committed Oct 15, 2024
1 parent d895cdb commit b5d448e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/aircraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ pub fn update_player_weapon_controls(
}
}

pub fn update_player_aircraft_controls(mut aircrafts: Query<&mut Aircraft, With<Player>>, input: Res<ButtonInput<KeyCode>>, time: Res<Time>) {
for mut aircraft in aircrafts.iter_mut() {
pub fn update_player_aircraft_controls(mut aircrafts: Query<(&mut Aircraft, &mut Transform), With<Player>>, input: Res<ButtonInput<KeyCode>>, time: Res<Time>) {
for (mut aircraft, mut transform) in aircrafts.iter_mut() {
// Throttle
// info!("Throttle: {}", aircraft.throttle);
if input.pressed(KeyCode::KeyW) {
Expand Down Expand Up @@ -253,5 +253,19 @@ pub fn update_player_aircraft_controls(mut aircrafts: Query<&mut Aircraft, With<
//TODO: Slew to 0 instead of hard reset
aircraft.yaw_force = 0.0;
}
//Debug
if input.pressed(KeyCode::KeyL) {
transform.rotate_y(-0.01);
}
if input.pressed(KeyCode::KeyJ) {
transform.rotate_y(0.01);
}
if input.pressed(KeyCode::KeyI) {
transform.rotate_x(-0.01);
}
if input.pressed(KeyCode::KeyK) {
transform.rotate_x(0.01);
}

}
}
4 changes: 2 additions & 2 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ pub fn spawn_player(mut commands: Commands,

// .insert(TransformBundle::from(Transform::from_xyz(0.0, 4.0, 0.0)));

spawn_sam(&mut commands, &asset_server, 100.0, 10.0, CoalitionType::RED);
spawn_sam(&mut commands, &asset_server, 10.0, 10.0, CoalitionType::RED);
spawn_sam(&mut commands, &asset_server, 3000.0, 10.0, CoalitionType::RED);
// spawn_sam(&mut commands, &asset_server, 10.0, 10.0, CoalitionType::RED);


}
Expand Down
4 changes: 4 additions & 0 deletions src/radar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ pub fn update_radar(

// if signal_strength + radar_cross_section > 1 then we are visible
let raw_return_signal = signal_strength_at_target + detectable.radar_cross_section;
info!("raw return: {}", raw_return_signal);

// Now check our orientation relative to the radar emitter,
// and attenuate the return signal depending on radar type and our orientation
let mut angular_difference = (detectable_transform.translation - radar_transform.translation).angle_between(detectable_transform.forward().as_vec3()).to_degrees();
if angular_difference > 90.0 {
angular_difference = (detectable_transform.translation - radar_transform.translation).angle_between(-detectable_transform.forward().as_vec3()).to_degrees();
}
angular_difference = 90.0 - angular_difference;
info!("angular difference: {}", angular_difference);
angular_difference = angular_difference / 90.0; //Make this range from 0.0 to 1.0

let mut effective_gain = radar_emitter.radar_gain;
Expand All @@ -119,6 +122,7 @@ pub fn update_radar(
effective_gain = radar_emitter.radar_gain * (1.0 - angular_difference);
}
}
info!("effective gain: {}", effective_gain);

let final_return_signal = raw_return_signal * effective_gain;
info!("Final return signal: {}", final_return_signal);
Expand Down
2 changes: 1 addition & 1 deletion src/sam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn spawn_sam(commands: &mut Commands,
.insert(Targetable)
.insert(RadarEmitter{
radar_type: RadarEmitterType::PULSE,
radar_gain: 100.0,
radar_gain: 10.0,
scan_interval: 3.0,
..default()
});
Expand Down

0 comments on commit b5d448e

Please sign in to comment.