Well, applying an upward impulse to a body is as simple as this:
// --- given the entity this script is applied to has a dynamic rigid body
// --- applied on press, put in in your script update method
if (this.app.keyboard.isPressed(pc.KEY_I)){
this.entity.rigidbody.applyImpulse(0, 10, 0);
}
You can check the API here, it allows you also to set an offset based on the entity center on the point where the impulse is applied. That may be useful for your drone car given it has offset engines:
Everything seems correct, I think you need to play with the impulse value. The 10 value was as an example, try adding an attribute to easily play with it and increase it.
So, I set the impulse to 100, and 1000, and I tried running the sim again, but no response. I tried adding an attribute for the impulse, but I have a feeling it’s not set up properly.
I’m new to coding, so I need a detailed explanation of everything if possible!
One error that I see know in your project is that you define the .update() in the DroneCarMovement script twice. Javascript is quite flexible to accept that with no error but it can’t hold two definitions for that function.
Meaning only your second update method is executing which basically does nothing since it’s empty.
Get rid of it and try again. Also you were missing Ammo hence the following error, press that button to Import Ammo and enable physics:
Next an additional issue:
Your Drone Car body is missing a collision component. A rigid body can’t work without a collision component.
I’ve made some changes here myself, forking your project, seems to be working as a starting point for you:
This is because you keep redefining your update function. All of the keyboard checks you’re doing should go under one copy of DroneCarMovement.prototype.update(). You can den separate them with else if statements.
As you using applyImpulse for movement, you are more likely to want to use applyTorqueImpulse instead of applyTorque to get that immediate rotation force.
Awesome! Thanks for all your guys’ help. I’m finally finished with all the controls including roll left and roll right The high value is necessary for torque, and applyTorqueImpulse works.
I’m moving on to the animations/dynamic-rocket-cage-movements-physics on a new forum post: