#how to add jumping to my game

2 messages · Page 1 of 1 (latest)

jagged flume
#

I was following a tutorial on how to make a platformer, and for some odd reason he neglected to show me how to make my character jump. I have tried to edit the code I already have to make it jump, and it didnt work. I am just starting out with this engine, so I know basically nothing. here is my code:

extends RigidBody3D

var mouse_sensitivity := 0.001
var twist_input := 0.0
var pitch_input := 0.0

@onready var twist_pivot := $TwistPivot
@onready var pitch_pivot := $TwistPivot/PitchPivot
# Called when the node enters the scene tree for the first time.
func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    var input := Vector3.ZERO
    input.x = Input.get_axis("move_left", "move_right")
    input.z = Input.get_axis("move_forward", "move_back")
    
    apply_central_force(twist_pivot.basis * input * 1200.0 * delta)
    
    if Input.is_action_just_pressed("ui_cancel"):
        Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
        
    twist_pivot.rotate_y(twist_input)
    pitch_pivot.rotate_x(pitch_input)
    pitch_pivot.rotation.x = clamp(
        pitch_pivot.rotation.x,
        deg_to_rad(-30),
        deg_to_rad(30)
    )
    twist_input = 0.0
    pitch_input = 0.0
    

func _unhandled_input(event: InputEvent) -> void:
    if event is InputEventMouseMotion:
        if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
            twist_input = -event.relative.x * mouse_sensitivity
            pitch_input = -event.relative.y * mouse_sensitivity
frosty stratus
#

have you tried using apply_force()?