Godot Version
4.6
Question
I was making movement script but the jump is not working ?
extends CharacterBody3D
const SPEED = 10
const JUMP_VELOCITY = 10
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready(): #cursor capture
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
# PROBLEM AT (5,1),(6,7) AND UPPER MID😭
func _unhandled_input(event):
if event is InputEventMouseMotion:
rotation.y -= event.screen_relative.x * 0.001
%Camera3D.rotation_degrees.x -= event.screen_relative.y * 0.1
%Camera3D.rotation_degrees.x = clamp(
%Camera3D.rotation_degrees.x, -60, 60
)
elif event.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
elif event.is_action_pressed("ui_accept"):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
var decel = SPEED * 3.5 * delta
if not is_on_floor():
velocity.y -= gravity * delta
if Input.is_action_pressed("jump") and is_on_floor():
velocity.y -= JUMP_VELOCITY
var input_dir = Input.get_vector("move_left","move_right","move_forward","move_back")
var direction = ( transform.basis * Vector3(input_dir.x, 0.0 , input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else :
velocity.x = move_toward(velocity.x, 0.0, decel)
velocity.z = move_toward(velocity.z, 0.0, decel)
move_and_slide()