2024-01-27 01:15:01 +01:00
|
|
|
extends CharacterBody3D
|
2024-01-27 00:05:04 +01:00
|
|
|
|
|
|
|
@export var color : Color = Color.DODGER_BLUE
|
2024-01-26 21:07:19 +01:00
|
|
|
|
|
|
|
@export var move_right_action := "move_right"
|
|
|
|
@export var move_left_action := "move_left"
|
|
|
|
@export var move_down_action := "move_down"
|
|
|
|
@export var move_up_action := "move_up"
|
|
|
|
@export var dash_action := "dash"
|
2024-01-27 01:15:01 +01:00
|
|
|
@export var bomb_action := "bomp"
|
2024-01-26 21:07:19 +01:00
|
|
|
|
|
|
|
@onready var geometry = $Geometry
|
|
|
|
|
2024-01-27 01:15:01 +01:00
|
|
|
signal bomb_triggered
|
|
|
|
|
2024-01-26 21:07:19 +01:00
|
|
|
var angle = 0
|
|
|
|
var is_dashing = false
|
|
|
|
var dash_time = 0
|
|
|
|
|
|
|
|
const SPEED = 5.0
|
|
|
|
const JUMP_VELOCITY = 4.5
|
|
|
|
const DASH_SPEED: float = 20
|
|
|
|
const DASH_DURATION: float = 0.2
|
|
|
|
|
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
|
|
|
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
# Add the gravity.
|
|
|
|
if not is_on_floor():
|
|
|
|
velocity.y -= gravity * delta
|
|
|
|
|
|
|
|
# Handle jump.
|
|
|
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
|
|
|
velocity.y = JUMP_VELOCITY
|
2024-01-27 01:15:01 +01:00
|
|
|
|
|
|
|
if Input.is_action_just_pressed(bomb_action):
|
|
|
|
emit_signal("bomb_triggered", self)
|
2024-01-26 21:07:19 +01:00
|
|
|
|
|
|
|
# Get the input direction and handle the movement/deceleration.
|
|
|
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
|
|
|
var input_dir = Input.get_vector(move_left_action, move_right_action, move_up_action, move_down_action)
|
|
|
|
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
|
|
if direction:
|
|
|
|
velocity.x = direction.x * SPEED
|
|
|
|
velocity.z = direction.z * SPEED
|
|
|
|
angle = direction.signed_angle_to(Vector3.FORWARD, Vector3.UP)
|
|
|
|
geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0))
|
|
|
|
else:
|
|
|
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
|
|
velocity.z = move_toward(velocity.z, 0, SPEED)
|
2024-01-27 00:05:04 +01:00
|
|
|
geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0))
|
2024-01-26 21:07:19 +01:00
|
|
|
|
|
|
|
if Input.is_action_just_pressed("dash_p1"):
|
|
|
|
is_dashing = true;
|
|
|
|
dash_time = DASH_DURATION
|
|
|
|
|
|
|
|
if is_dashing:
|
|
|
|
velocity.x = sin(angle) * DASH_SPEED
|
|
|
|
velocity.z = -cos(angle) * DASH_SPEED
|
|
|
|
|
|
|
|
geometry.global_basis = Basis.from_euler(Vector3(-0.3, -angle, 0))
|
|
|
|
|
|
|
|
dash_time -= delta
|
|
|
|
if dash_time <= 0:
|
|
|
|
is_dashing = false
|
|
|
|
|
|
|
|
move_and_slide()
|