initial experiments
This commit is contained in:
commit
c90da1eda2
17 changed files with 259 additions and 0 deletions
30
objects/player/player.gd
Normal file
30
objects/player/player.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
|
||||
@export var walk_speed: float
|
||||
@export var gravity: float
|
||||
@export var jump_force: float
|
||||
|
||||
@export var level_path: Path3D
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# snap player horizontally to path
|
||||
var path_offset = level_path.curve.get_closest_offset(level_path.to_local(global_position))
|
||||
var path_trans = level_path.curve.sample_baked_with_rotation(path_offset, true)
|
||||
global_position.x = path_trans.origin.x
|
||||
global_position.z = path_trans.origin.z
|
||||
global_transform.basis.x = -path_trans.basis.x
|
||||
global_transform.basis.z = -path_trans.basis.z
|
||||
|
||||
# horizontal movement
|
||||
var h_movement = global_transform.basis.z * Input.get_axis(&"walk_left", &"walk_right") * walk_speed
|
||||
velocity.x = h_movement.x
|
||||
velocity.z = h_movement.z
|
||||
|
||||
# vertical movement
|
||||
velocity.y -= gravity * delta
|
||||
if Input.is_action_just_pressed(&"jump"):
|
||||
velocity.y = jump_force
|
||||
|
||||
move_and_slide()
|
Loading…
Add table
Add a link
Reference in a new issue