Freecam Mode

This commit is contained in:
Patrick_Pluto 2024-12-11 19:25:39 +01:00
parent e3d9b04a64
commit 0fa362aed4
2 changed files with 28 additions and 4 deletions

View file

@ -8,6 +8,7 @@ const SPEED: float = 5.0
const JUMP_VELOCITY: float = 4.5
var activated: bool = false
var freecam: bool = false
@onready
var camera: Camera3D = $Camera3D
@ -22,11 +23,24 @@ func _ready() -> void:
func _physics_process(delta: float) -> void:
if activated:
if not is_on_floor():
velocity += get_gravity() * delta
if !freecam:
if not is_on_floor():
velocity += get_gravity() * delta
if !freecam:
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
if freecam:
if Input.is_action_pressed("jump"):
velocity.y = JUMP_VELOCITY
elif Input.is_action_pressed("descend"):
velocity.y = -JUMP_VELOCITY
else:
velocity.y = 0
if Input.is_action_just_pressed("freecam"):
freecam = !freecam
var input_dir: Vector2 = Input.get_vector("move_left", "move_right", "move_forwards", "move_backwards")
var direction: Vector3 = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()