VehicleBody - How to control it when it's jumping?

javzerojavzero Posts: 2Member
edited January 2019 in 3D

Hi all!. I made a car using VehicleBody. When you make it jump down a ramp you lose control while it is in the air.
I'm trying to build a mechanic that allows you to rotate it a bit in the air to land in a better way. (Like GTA and those kind of games)

I partialy achieve this by checking if the car is not grounded and if so you can rotate it with the same control keys. (WASD)

I am using something like this:
(If car is in air):

  if Input.is_action_pressed("Forward"):
      angular_velocity.x  = -1
  if Input.is_action_pressed("Reverse"):
      angular_velocity.x = 1
  if Input.is_action_pressed("Left"):
      angular_velocity.z = 2
  if Input.is_action_pressed("Right"):
      angular_velocity.z = -2

The problems is that my car rotates relative to world or relative to axis (I dont know).
When you jump towards the X axis (or lets say North) and hit "Forward key" you can control pitch.
But when you jump towards the Y axis (or lets say East) and hit "Forward Key" you can control rol.

I want to control allways pitch with forward and backwards key and rol with left and right.
How can I manage to do that?

Maybe my explanations is a little confusing (Im not an english speaker).
Let me know if more info is needed.


Tags :


  • CalinouCalinou Posts: 403Admin Godot Developer

    I think you could make use of 3D transforms and some vector tricks with the basis to achieve that.

  • javzerojavzero Posts: 2Member

    If I modify the transform of the car it looses speed in the air (kind of slowmotion effect). That's why I'm trying to use something like add force or apply velocity. But I can't find how to apply forces relative to vehicle orientation.
    I mean, I cant't find the right implementation in the docs.

  • wombatstampedewombatstampede Posts: 173Member

    There's an apply_torque method which probably also applies to VehicleBody (via RigidBody).
    Or you use two times apply_impulse (think of two fingers on a fidget spinner).

    Here's an answer in the q&a which still uses apply_impulse but mentions apply_torque:

    Perhaps that helps?

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file