Loads of stuff
This commit is contained in:
parent
f3af522683
commit
66ce3ff503
413 changed files with 14802 additions and 0 deletions
51
Entities/Player/scripts/player.gd
Normal file
51
Entities/Player/scripts/player.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
@export var speed = 2
|
||||
@export var fall_acceleration = 75
|
||||
|
||||
var target_velocity = Vector3.ZERO
|
||||
|
||||
func _ready() -> void:
|
||||
position = Vector3.ZERO
|
||||
|
||||
func _physics_process(delta):
|
||||
%MultiMesh3D.set("instance_shader_parameters/player_position", position)
|
||||
%TileGround.update_chunks(position)
|
||||
|
||||
# We create a local variable to store the input direction.
|
||||
var direction = Vector3.ZERO
|
||||
|
||||
# We check for each move input and update the direction accordingly.
|
||||
if Input.is_action_pressed("move_right"):
|
||||
direction.x += 1
|
||||
if Input.is_action_pressed("move_left"):
|
||||
direction.x -= 1
|
||||
if Input.is_action_pressed("move_back"):
|
||||
# Notice how we are working with the vector's x and z axes.
|
||||
# In 3D, the XZ plane is the ground plane.
|
||||
direction.z += 1
|
||||
if Input.is_action_pressed("move_forward"):
|
||||
direction.z -= 1
|
||||
|
||||
if direction != Vector3.ZERO:
|
||||
direction = direction.normalized()
|
||||
# Setting the basis property will affect the rotation of the node.
|
||||
$Pivot.basis = Basis.looking_at(-direction)
|
||||
|
||||
# Ground Velocity
|
||||
target_velocity.x = direction.x * speed
|
||||
target_velocity.z = direction.z * speed
|
||||
|
||||
# Vertical Velocity
|
||||
if not is_on_floor(): # If in the air, fall towards the floor. Literally gravity
|
||||
target_velocity.y = target_velocity.y - (fall_acceleration * delta)
|
||||
|
||||
# Moving the Character
|
||||
velocity = target_velocity
|
||||
|
||||
if direction != Vector3.ZERO:
|
||||
%PlayerAnimationPlayer.play('basic-movement/walk')
|
||||
else:
|
||||
%PlayerAnimationPlayer.play('basic-movement/idle')
|
||||
|
||||
move_and_slide()
|
||||
Loading…
Add table
Add a link
Reference in a new issue