Flying Car Physics

https://playcanvas.com/editor/project/800196

I am working on the physics of a drone car in my project. I was wondering if anyone knows a good reference at PlayCanvas for a drone, plane, or helicopter that would most closely match the needs of the following physics.







Since the drone car hovers in mid-air, there would be a constant Force opposing gravity at all times.

I know I can do this by adding box Collisions: and then controlling the force vector on each of the Rigidbodies.

I also understand the Physics in English, but I need some help translating the concepts into JavaScript. Any help in terms of references to other projects, raw scripting, or advice regarding this project would be much appreciated!

Thanks!

Hi @Lorenzmotors,

I haven’t done or seen something similar to point you to an example. It’s a complex structure to drive with physics but definitely it’s doable, and I imagine the way you are planning in doing it (with boxes).

If you would like a more advanced read you can check the following Bullet based example:

Internally PlayCanvas uses a Javascript port of the Bullet physics engine.

Took a bit to feel comfortable wrapping back around to this topic. Currently, I’m trying to code the dronecar to stabilize in the air at a certain height. Gravity is enabled, so the dronecar gets pulled down to the ground. Is there at least a work-around in JavaScript to make it seem like it’s hovering?

To have an object defy gravity and hover, you can apply one or more upward directed forces to to it:

const power = 100;
const forceUp = new pc.Vec3().copy(pc.Vec3.UP).scale(power);

this.entity.rigidbody.applyForce(forceUp);
2 Likes

Thank you. I added it under DronecarControls.prototype.update = function(dt) under all the variables, and it worked! That’s awesome. I was wondering if there is a way to always have the dronecar parallel to the ground. As you can see in the beginning of the video how it is always, sort of, parallel to the ground, and then at the end of the video it starts spinning out of control.

Is there a way to prevent the dronecar from spinning out of control so that it is always parallel to the ground?

You can do that by setting the angular factor for all axis to 0, that way there will no angular momentum applied to the rigid body. Meaning it won’t rotate no matter the forces applied.

image