Games [XUI2D] Monster Truck Example - WheelJoint

Erel

B4X founder
Staff member
Licensed User
Longtime User

The WheelJoint is similar to a RevoluteJoint with a spring that allows the bodies to move along a defined axis.

The movement is done by enabled the joint motors.

If you run it with debug drawing enabled you will see two additional fixtures:

SS-2018-08-28_17.24.52.png


The bottom one is a heavy fixture that helps with stabilizing the car. It is destroyed after 100 meters to make the car crash.

The top one is very light and it used to find out when the car rolled over.

Getting the physics to behave nicely was challenging and it still needs a bit fine tuning.
There are many parameters that affect the behavior. The hills in this example are too steep. It would have been better to use different tile set with more gentle heels.

The example will be added to the examples pack.
https://www.b4x.com/android/forum/threads/xui2d-example-pack.96454/

Tileset credit: http://www.kenney.nl
 

sorex

Expert
Licensed User
Longtime User
Great!

What is wonder is if you need to set a maximum left/right rotation angle on the springs.
The wheel would go over the car otherwise, not?

Is there a specific reason why the car polygon doesn't go around the car (car+wheel caps) only? (not including the wheel centers)
 

Cableguy

Expert
Licensed User
Longtime User
Cool!

I hate to be that guy but, it's actually Monster Truck, not trunk. ;)
It could be worse... truck... trunck.. . Drunk...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
What is wonder is if you need to set a maximum left/right rotation angle on the springs.
The wheel would go over the car otherwise, not?
The joint allows the wheel to turn around themselves. They will not be able to turn if there were limits (this is why there is no limit feature in WheelJoint).

Is there a specific reason why the car polygon doesn't go around the car (car+wheel caps) only?
You should try it. If the car polygon is too low then it will hit the ground.
 

sorex

Expert
Licensed User
Longtime User
I will play around with it.

Thanks for the new 0.98 Xui2D update (which is required for this).
 

sorex

Expert
Licensed User
Longtime User
I ran it last night and it's very smooth & realistic, well done.
 
Last edited:

wyatt420

Member
Licensed User
Longtime User
how can you check the truck is on the ground? do you need to add sensors to the wheels and check wheel/ground collision?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You don't need to add sensors.
Add this code to the Tick sub:
B4X:
If FrontJoint.BodyB.GetContactList(True).Size > 0 Or RearJoint.BodyB.GetContactList(True).Size > 0 Then
   Log("on ground")
Else
   Log("in air")
End If
It tests whether one of the wheels touches something.
 
Top