• 3D
  • How to get a position in space and use it as the point from which to add a force to a RigidBody?

Hey guys, I need a little help, transforms confuse the heck out of me and my brain is frying. My current code works fine, but I want to change it a bit. I just don't know how.

I've been using this code to push a rigid body car forward:

var point = -car_body.global_transform.basis.y*1.15  # I could just add 0.15, I guess, but yea...
car_body.add_force(-car_body.global_transform.basis.z * power, point)

That gets me a point below the RigidBody (if I understand correctly what I'm doing), which helps tilt the car backward when accelerating.

But I want to try applying smaller forces from the positions of the wheels, instead. The question is, how do I get the position of a wheel relative to the car body, so I can use it in point?

So the vectors you send to physics functions are in world space, but centered on the objects origin. So if you send (1, 1, 0) that will be 1 meter to the upper-right, in world space, relative to the car center point (or the wheel or whatever object). To get the wheel position, just get the global transform of the wheel and subtract the global transform of the car.

I presume you meant the transform origins. Seems to be working. I managed to add the wheel radius to it, so the point is actually at the bottom of the wheel.

lf_wheel_point = (lf_wheel.transform.origin-car_body.transform.basis.y*wheel_radius) - car_body.transform.origin

I used the local transforms because my debugger was drawing the points wrongly with global ones, for some reason.