Is it possible to move a KinematicBody at an angle in a 3D game in a way to create a Rocket Jump?

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

I found it kind of hard to work on a character based on RigidBody, so I tried using KinematicBody instead. I just want to know if it’s possible to move a character vertically at an angle with any speed variable. Sorry for the lack of code, just assessing my options. Any example would be great.

:bust_in_silhouette: Reply From: RedBlueCarrots

Consider adapting a simple controller like this as the base for your character controller (It’s in 2d but the same principles apply for 3D).

Then, if you want a rocket jump, it would be very similar to a jump, just instead of just changing the velocity in the y axis, you would change it in the x and z as well.

For Example:

if Input.is_action_just_pressed("rocket_jump"):
        if is_on_floor(): #May or may not need this check depending on what you want in your game
            velocity.y = 0
            velocity += rocket_speed * rocket_angle

Where rocketspeed is a predefined float value dictating the power of the rocket, and rocketangle is a normalized vector3 which dictates the launch direction.

Hope this helps, I’m happy to answer any more questions you may have.

Could you elaborate more on that Vector3? Like how I’d assign values to it if possible. Also thanks in advance, kind of a novice here.

Makubx | 2021-04-22 15:37

A vector3 contains an x, y, and z value. By giving values for x, y, and z, you can use this to determine the “direction” of the vector.

For example:
Vector3(1, 0, 0) is a vector pointing at the positive x direction
Vector3(0, 1, 0) is a vector pointing upwards in the y direction
Vector3(1, 1, 0) is a vector pointing both in the forward x and positive y direction. (And as x and y are equal this will be at a 45 degree angle)

The only issue with the last one is that - because of Pythagoras’ theorem - it has a length of sqrt(2), not 1. By “normalizing” the vector, this essentially turns this vector into a length of 1, so the speed will remain constant for any direction.

Syntax in godot is Vector3(x, y, z).normalized()

Hope that clarified a little

RedBlueCarrots | 2021-04-23 03:21