v4.2.1
I’m trying to make the player a RigidBody3D node however I am struggling to find alternatives to is_on_floor for a jumping script that I’m trying to use and to add on I am relatively new to scripting so any general help would appreciated as well
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
func _ready() → void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
var input := Vector3.ZERO
input.x = Input.get_axis("move_left", "move_right")
input.z = Input.get_axis("move_forward", "move_backwards")
if Input.is_action_pressed("Run"):
apply_central_force(twist_pivot.global_basis * input * 1700.0 * delta)
if Input.is_action_pressed("Crouch"):
apply_central_force(twist_pivot.global_basis * input * -600.0 * delta)
apply_central_force(twist_pivot.global_basis * input * 1500.0 * delta)
if Input.is_action_just_pressed("jump"):
apply_central_impulse(Vector3(0, 10, 0))
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