This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When airplanes reached the end of their flight plan, some random nodes were added to the plan to keep the airplane moving. When that happened, however, the rotation of the airplane's sprite was not updated. This resulted in airplanes moving sideways for a step in their flight plan, before being rotated correctly during the next step. To fix this, a new system has been introduced that checks the rotation of each airplane on every frame. This can be optimized in the future to occur only when the flight plan of an airplane is updated.
- Loading branch information
Showing
5 changed files
with
44 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use bevy::prelude::*; | ||
|
||
use crate::components::{FlightPlan, TravelledRoute}; | ||
use crate::map::Direction; | ||
|
||
pub fn rotate_airplane(mut query: Query<(&mut FlightPlan, &mut Transform, &mut TravelledRoute)>) { | ||
for (flight_plan, mut transform, travelled_route) in query.iter_mut() { | ||
let last_point = travelled_route | ||
.get() | ||
.last() | ||
.expect("travelled route must not be empty") | ||
.as_point(); | ||
|
||
let next_point = match flight_plan.next() { | ||
Some(node) => node.as_point(), | ||
None => continue, | ||
}; | ||
|
||
let direction = Direction::between(&next_point, &last_point); | ||
transform.rotation = Quat::from_rotation_z(direction.to_degree().to_radians()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters