Improved environment

This commit is contained in:
2024-01-16 23:01:16 +01:00
parent 8f0f3d9998
commit 6934f2936b
16 changed files with 274 additions and 96 deletions

View File

@ -1,7 +1,35 @@
extends Node3D
class_name Player
extends CharacterBody3D
func _ready():
pass
const MOVE_SPEED = 4.5
const JUMP_VELOCITY = 4.5
const DECELERATE = 0.75
func _process(_delta):
pass
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var move: Vector2
func _input(_event):
move = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
func _physics_process(delta):
movement()
fall(delta)
move_and_slide()
func movement():
var direction = (Global.camera.transform.basis * Vector3(move.x, 0, move.y)).normalized()
# var direction = Vector3(move.x, 0, move.y).normalized()
if direction:
velocity.x = direction.x * MOVE_SPEED
velocity.z = direction.z * MOVE_SPEED
else:
velocity.x *= DECELERATE
velocity.z *= DECELERATE
func fall(delta):
if is_on_floor():
if Input.is_action_just_pressed("jump"):
velocity.y = JUMP_VELOCITY
else:
velocity.y -= gravity * delta