Skip to content

Commit

Permalink
Fix missile behavior by adding can_rotate variable to mobs (#164)
Browse files Browse the repository at this point in the history
* fix missile behavior by adding can_rotate variable to mobs, conditionally added locked axes component

* match target_position for missile in outer match statement
  • Loading branch information
cdsupina committed Mar 4, 2024
1 parent 66306c4 commit 3bbcae1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions assets/data/mobs.ron
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@
mob_behaviors: [ExplodeOnImpact, DealDamageToPlayerOnImpact, ReceiveDamageOnImpact, DieAtZeroHealth],
acceleration: (12.0, 2.0),
deceleration: (5.0, 5.0),
can_rotate: true,
speed: (150.0, 150.0),
angular_acceleration: 0.5,
angular_speed: 1.8,
Expand Down
16 changes: 7 additions & 9 deletions src/spawnable/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ pub fn spawnable_execute_behavior_system(
SpawnableBehavior::MoveLeft => {
move_left(&spawnable_component, &mut rb_vel);
}
SpawnableBehavior::RotateToTarget(target_position) => {
if let Some(target_position) = target_position {
rotate_to_target(
spawnable_transform,
target_position,
&spawnable_component,
&mut rb_vel,
);
}
SpawnableBehavior::RotateToTarget(Some(target_position)) => {
rotate_to_target(
spawnable_transform,
target_position,
&spawnable_component,
&mut rb_vel,
);
}
SpawnableBehavior::MoveForward => {
move_forward(spawnable_transform, &spawnable_component, &mut rb_vel);
Expand Down
8 changes: 7 additions & 1 deletion src/spawnable/mob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ pub struct MobData {
pub mob_segment_behaviors: Option<
HashMap<MobSegmentControlBehavior, HashMap<MobSegmentType, Vec<MobSegmentBehavior>>>,
>,
/// Whether the mob can rotate on its z axis
#[serde(default)]
pub can_rotate: bool,
/// Acceleration stat
#[serde(default)]
pub acceleration: Vec2,
Expand Down Expand Up @@ -369,7 +372,6 @@ pub fn spawn_mob(
direction: mob_data.animation.direction.clone(),
})
.insert(RigidBody::Dynamic)
.insert(LockedAxes::ROTATION_LOCKED)
.insert(Velocity::from(mob_data.initial_motion.clone()))
.insert(Collider::compound(
mob_data
Expand Down Expand Up @@ -398,6 +400,10 @@ pub fn spawn_mob(
mob.insert(BossComponent);
}

if !mob_data.can_rotate {
mob.insert(LockedAxes::ROTATION_LOCKED);
}

if let Some(weapon_component) = mob_data.get_weapon_component() {
mob.insert(weapon_component);
}
Expand Down

0 comments on commit 3bbcae1

Please sign in to comment.