Well, its kinda harder to add jumping due to needing collision detection, which is probably why most use the KinematicBody node since it has functions to move and take the physics world into account.
For jumping with a Spatial node, you will need to apply a vertical velocity and gravity. You’ll want to have it where the detection method you are using for seeing the ground (a raycast, based on the code above) detects the ground you cancel out the vertical velocity and detect jumping input.
Then, if the jump key is pressed, you set the vertical velocity to a big positive number.
When the car is not on the ground, you’ll want to apply the vertical velocity and gravity, moving the car by the velocity amount and making the velocity get smaller and smaller. This should, I think, give you jumping.
To put it into pseudo code, it would look something like this:
var vertical_velocity = 0
const GRAVITY = 4.0
func _process(delta):
# other code here
if ground_ray.is_colliding() == true:
vertical_velocity = 0
if Input.is_action_just_pressed(“jump”):
vertical_velocity = 100
global_transform.origin.y += vertical_velocity * delta
else:
global_transform.origin.y += vertical_velocity * delta
vertical_velocity -= delta * GRAVITY
I think that should work.
For drifting, that would requiring have velocity for horizontal movement, acceleration and deceleration. Right off I’m not 100% sure on how to program it though and you may want to look into using a KinematicBody or RigidBody node at that point, as it can help with a lot of the heavy lifting and physics calculations.
Also
This discussion was caught in the moderation queue since you have not confirmed your account yet.
Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.
(Note: You do not need to repost, the discussion has been moved out and is visible now)
If you need any help, please let us know! You can find ways to contact forum staff on the Contact page. Thanks! :smile: