Hello, I am trying to use nphysics to prototype my game engine and I cannot figure out how to make objects which move by their own. Imagine we have a rigid multibody (like human figure from the examples) and one of its subbodies is applying acceleration to all of the body (legs move, for example). Cannot find anything in the documentation, what is the correct way to do that?
I am reading about the motors, but they are joint feature, imagine we have a rocket that have an engine that creates thrust, this force is applied to the sub-body, not to the joint. How can I do it?
P.S. I see there is a apply_force method for RigidBody, but cannot find good examples how it could be used, any chance to have any?
P.P.S. Scratch it, now I have a real issue, I am trying to apply either force or velocity to rigid body and I am having a trouble, I am pretty new to Rust, I am sure I am doing something stupid, will appreciate some help.
The code (i am modifying example with balls):
let &mut rigid_body = world.rigid_body(handle).unwrap().borrow_mut();
rigid_body.set_velocity(Velocity2::new(Vector2::new(0.1 as f32 * i as f32, 0.1 as f32 * j as f32), 0.0));
I am getting an error: cannot borrow (rigid_body) as mutable. But the rigid_body is mutable borrow. I tried different approaches, but obviously I dont understand how borrow mutability works here. Can you suggest how should I do it?
P.P.P.S Pain! I found example with that code
let platform_handle = world.add_rigid_body(pos, Inertia::zero(), Point2::origin());
{
let rb = world.rigid_body_mut(platform_handle).unwrap();
rb.set_status(BodyStatus::Kinematic);
rb.set_velocity(Velocity::linear(1.0, 0.0));
}
I wish I have something like this somewhere in the doco. Will try this solution
P.P.P.S. Sorry for all of that. The approacj works, I didnt know the function rigid_body_mut, now I am looking into making objects move by themselves. I am thinking to provide Force that will change in time, wonder if there is some good example about that, it looks pretty common case in game engine. Wonder if I am solving it the wrong way, would be happy to hear anything regarding that.