Rigid Bodys intereaction

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Pelli

Hi, I have some nob questions. I am making a game where you are a car and you have to transport things. I am making a prototype with my car as a Rigid Body and a box as a Rigid Body too. I am facing 2 issues:

First when accelerating my car the box that it is transporting tends to roll back and fall immediately, so you can´t transport anything. How I can make it grab a little so the box only fall when I am at certain speed?

An example:


Second issue appear when the box is on the corner of my car, the car begins to tilt due to the weight of the box,How can I prevent the car from suffering that weight?

An example

box weight

For both problems I tried changing gravity, mass, height and friction but I can´t see a difference

Have you taking a physics course yet? I think what you’re trying to accomplish is going to be very difficult without being able to draw a Free Body Diagram of your car and box interaction and a baseline knowledge of physics. I would suggest following along with the first three modules here: https://www.khanacademy.org/science/high-school-physics to get a baseline understanding of motion in physics.

I think ultimately what you’re going to want is the platform of your car (where the boxes rest) to be it’s own RigidBody2D that rests on its wheels which are their own RigidBody2D’s. Alternatively you can calculate the torque applied to your car at runtime and use the apply_torque_impulse() function to apply that torque to your car accordingly. This is going to allow you to achieve the effect you described in your second issue. (You’re going to need to be clever about how you keep the wheels of the car in sync with the platform of the car though.) The first issue is all about how you’re applying the forces to the RigidBody2D box, until you’re able to draw a Free Body Diagram of your problem it’s just going to be a guessing game which numbers to use for what and what calculations to perform.

timothybrentwood | 2021-04-28 13:47

:bust_in_silhouette: Reply From: stalker2106

Physics work just the way they work.

You could bypass the behaviour by implementing in _physics_process(state) function some code that will make use of rigidbody.get_colliding_bodies() to change linear velocity of your crate to the one of your truck, to prevent it from falling but it might look clunky in the end. You might just want to have a simpler approach!