Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Constrain maximum speed of object #311

Answered by jcornaz
cswinter asked this question in Q&A
Discussion options

You must be logged in to vote

At the moment, there is no built-in way to do that.

What you can do is make sure to clamp the velocity at each update:

#[derive(Component)]
struct MaxSpeed(f32);

fn enforce_max_velocity(mut bodies: Query<&mut Velocity, &MaxSpeed>) {
  for (mut velocity, MaxSpeed(max_speed)) in bodies.iter_mut() {
    velocity.linear = velocity.linear.clamp_length_max(max_speed);
  }
}

Of course, we could add a MaxSpeed component in heron.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cswinter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants