refactor: minor code refactor so it looks slightly better
This commit is contained in:
parent
8c88cf9cac
commit
742dc85414
@ -83,9 +83,9 @@ impl Boid for Boid2D {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn apply_force(&mut self, force: Vec3) {
|
fn apply_force(&mut self, force: Vec3) {
|
||||||
self.vel += force.xy();
|
self.vel += force.xy();
|
||||||
let new_vel = self.vel.clamp_length_max(self.props.max_speed);
|
self.vel = self.vel.clamp_length_max(self.props.max_speed);
|
||||||
self.vel = new_vel;
|
let force_to_apply = Vector2::new(self.vel.x, self.vel.y);
|
||||||
self.base_mut().translate(Vector2::new(new_vel.x, new_vel.y));
|
self.base_mut().translate(force_to_apply);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -82,10 +82,9 @@ impl Boid for Boid3D {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn apply_force(&mut self, force: Vec3) {
|
fn apply_force(&mut self, force: Vec3) {
|
||||||
self.vel += force;
|
self.vel += force;
|
||||||
let new_vel = self.vel.clamp_length_max(self.props.max_speed);
|
self.vel = self.vel.clamp_length_max(self.props.max_speed);
|
||||||
self.vel = new_vel;
|
let force_to_apply = Vector3::new(self.vel.x, self.vel.y, self.vel.z);
|
||||||
self.base_mut()
|
self.base_mut().translate(force_to_apply);
|
||||||
.translate(Vector3::new(new_vel.x, new_vel.y, new_vel.z));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -28,4 +28,4 @@ pub struct BoidProperties {
|
|||||||
#[init(val = 0.8)]
|
#[init(val = 0.8)]
|
||||||
/// How much to follow a flock target (if there is one).
|
/// How much to follow a flock target (if there is one).
|
||||||
pub targeting: f32,
|
pub targeting: f32,
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,4 @@ pub struct FlockProperties {
|
|||||||
#[init(val = 2500.0)]
|
#[init(val = 2500.0)]
|
||||||
/// Distance (squared) to apply cohesion force between boids in a flock.
|
/// Distance (squared) to apply cohesion force between boids in a flock.
|
||||||
pub goal_cohesion: f32,
|
pub goal_cohesion: f32,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user