Vehicle Physics Example

@will I am super stoked to play around with your demo. I have a couple questions. What was the model built in, our shop uses Blender and I believer the bones handle the X/Y axis differently, and also just trying to understand how the bones are rigged. Thanks for any help you can offer.

There’s an engine only example of this: http://playcanvas.github.io/#physics/vehicle.html

I don’t think there needs to be a specific rig. You could have the main chassis as one entity and the wheels as 4 children entities.

I am working on a project for a automobile company so I really need to be able to make the car feel properly responsive. I am also a bit confused by some of the code in terms of how the example you just shared relates to the more fleshed out version that was on your projects page.

The engine only example was to show the other ways that the vehicle physics can be implemented and that it isn’t dependent on a rig. It uses the same vehicle.js script but a different graphical representation of the vehicle.

As long as the wheels are separate mesh instances/graph nodes/entities, they can be mapped to the physics representation.

All the vehicle-graphics.js code does is find the graph node of the wheel and copy the position and rotation of the physics representation: https://playcanvas.com/editor/code/643289?tabs=33521214

The vehicle hierarchy in the scene if to make the physics compound rigidbody
image

The part I would be careful with is the orientation of the wheels in the model since the rotation is copied from the physics. What it should be I’m not 100% but should be pretty easy to work out

Just forked the project to show how the wheels need to be orientated to work:

https://playcanvas.com/editor/scene/970480

Could I possibly fork this example?

Yeah, go right ahead

Thanks so much. I am the swiss-army knife at the shop and so I am no expert at 3-D, but I handle most of the intense interactives. I tend to make more 2-D Sprite games so some of this I “get” but it takes a bit to see the relationships. Thanks for you help!

One more question, is there any explanation about what the suspension variables are and the min and max?

One question on this, as you really are the resident expert, I removed the mesh surface and put in a plane and the car won’t move on it, even though I copied the same rigidbody/collision info. Any ideas?

it also will list to one side

I don’t really think there is a min/max. You will have to play with the values to get them ‘right’. The suspensionRestLength is probably the one that makes the most sense as it’s the world length of the spring to the chassis.

At a guess (without being able to see the project), the plane entity doesn’t have collision and rigidbody setup and/or the vehicle graphic entity hasn’t been setup properly with the vehicle physics.

List?

Can I send you a link? Nothing shakes on the mesh surface that was in the original project, but once i use a native object(a cube) with collision detection and static rigid body it starts to shake.

@yaustar https://playcanvas.com/editor/scene/970487

The box was just too large, especially on the Y. Here’s an example with something more usable: https://playcanvas.com/editor/scene/971080

The wheels still shake a bit, not sure how to fix that tbh. You might have to play with the values or the physics a bit.

Do you know why making the surface Y that large would cause that?

The problem is that i need a large space for it to drive in. and once I make the surface wider it throws everything off

You may need to import a tessellated mesh then in that case. A large default box with create huge polygons which the Bullet physics engine seems to be struggling with the vehicle raycast.

I was going to message you, that toally did the trick.