I’m using KX_VehicleWrapper which means setting the wheels to “No Collision” in the physics settings. However I need to detect collisions with the wheels so I can set up tyre tracks and dust/sparks from contact with elements in the game. Is there any way to do this?
Cast a ray from their positions.
Thanks for the reply. I can not get consistent results using the ray sensor. I set it up to toggle a boolean property when the wheels are touching the ground so it can make tracks/dust, but I want it to change to False when the wheel is in the air. It sometimes changes and sometimes not. I think probably because the wheels are spinning and the ray axis is always changing (?)
You must make sure to cast using script. And cast in relation to car.
Thanks for the idea. Working on it now.
Nope, it just doesn’t work for me. Problems: I want to be able to monitor each wheel individually so having a Ray on the car won’t tell me if, say, the right front wheel is in contact with the ground or not. Also, I want to detect contact with the ground which is a large contoured plane, so detecting the origin of the plane doesn’t help with whether each wheel is touching a particular bump or hollow at a particular point on the plane. Thanks again for the idea but I continue to “work on it”
Have rays on the wheels. Each wheel cast a ray along car’s Z vector. Than use it. Make sure that you cast a ray which is around 2 or 3 cm longer than wheel radius.
Well, here’s what I’ve managed so far:
... hit = car.rayCast([wheel.worldPosition.x, wheel.worldPosition.y, car.worldPosition.z-1.95], wheel.worldPosition, 1.0, "ground", 1, 0, 0) if hit: trackSize = int(math.sqrt(len(track)/4))...
While iterating through each of the wheels I am rayCasting to the ground at the point where each wheel position is but from the car’s z position, adjusted to ground level (car.worldPosition.z-1.95). This is an attempt to detect the presence of “ground” in a sculpted landscape. That is, the origin of the ground object may be [0, 0, 0], but the vehicle might be on an elevated part of the mesh at, say [0, 0, 3]. If I use a flat ground plane and set the z coordinate of the rayCast “to” parameter to 0.0, it works perfectly. When the wheels lift off the ground there are no tracks and as soon as they make contact again it starts. But there are no perfectly flat landscapes and as soon as I contour the ground the track laying algorithm gets messed up - sometimes works, sometimes doesn’t. Thanks to your suggestions I’m getting closer, but still some work to do.
So, TL;DR - have got rayCasting happening from each wheel to the ground and perfect track marks on flat landscape. Next is to get the same on a plane landscaped with hills and valleys.
That may require realtime texture systems, e.g. real time stencil mapping or using vertex colors for texture sets…
Just a bump to see if there are any other ideas out there. I notice plenty of views so I’m guessing this is something of interest to quite a few people. Essentially I’m trying to get my vehicle to appear to interact with the ground (leave tracks, throw up dust etc). Using rayCast I can get perfect results on a flat plane. I am using rayCast from point ([x, y, z] of each wheel position at each time step) to point ([x, y, z] of the point on the ground mesh below each wheel). As soon as I contour the ground mesh however, the ray fails to detect the mesh. Code example in earlier post.
It’s complex for me in this case. While I am making my physics system, I use rays anyways. I can just access them:D