Games [XUI2D] Monster Truck Example - WheelJoint

Discussion in 'Game Development' started by Erel, Aug 28, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed 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:

    [​IMG]

    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Just made an update. In some cases it took sometime for the car to start moving. With debug drawing I found that it happened when the car is sleeping.

    So the solution is to uncheck the 'allow sleep' for the car and wheels:

    [​IMG]
     
    Mashiane and NJDude like this.
  3. NJDude

    NJDude Expert Licensed User

    Cool!

    I hate to be that guy but, it's actually Monster Truck, not trunk. ;)
     
  4. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    Extraordinary!!! rest a little EREL .... jejeje;)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Thank you for being that guy!
     
  6. sorex

    sorex Expert Licensed 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)
     
  7. Cableguy

    Cableguy Expert Licensed User

    It could be worse... truck... trunck.. . Drunk...
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    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).

    You should try it. If the car polygon is too low then it will hit the ground.
     
    Johan Hormaza likes this.
  9. sorex

    sorex Expert Licensed User

    I will play around with it.

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

    sorex Expert Licensed User

    I ran it last night and it's very smooth & realistic, well done.
     
    Last edited: Aug 29, 2018
    Erel likes this.
  11. LucaMs

    LucaMs Expert Licensed User

    For the moment I have not used XUI2D, so my question is certainly not very inherent the topic: the poor quality (resolution) of the vehicle to what is due?
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    It is a small sprite. The video is taken from an iPhone. It looks better on the device.
     
  13. LucaMs

    LucaMs Expert Licensed User

    I would choose a bigger image to post a better video ;)
     
  14. wyatt420

    wyatt420 Member Licensed 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?
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    You don't need to add sensors.
    Add this code to the Tick sub:
    Code:
    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.
     
    wyatt420 likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice