extends CharacterBody3D
@export var SPEED = 5.0 #歩く速度
@export var DASH_SPEED = 10.0 #走る速度
const JUMP_VELOCITY = 4.5
@onready var MOVE_SPEED = SPEED #速度管理、デフォルトで歩く速度を設定
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("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# 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("left", "right", "up", "down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * MOVE_SPEED #SPEEDからMOVE_SPEEDに変更
velocity.z = direction.z * MOVE_SPEED #SPEEDからMOVE_SPEEDに変更
# --------------- 追加 ---------------
if Input.is_action_just_pressed("dash"): #SHIFTキーを押した時にMOVE_SPEEDを走る速度にする
MOVE_SPEED = DASH_SPEED
if Input.is_action_just_released("dash"): #SHIFTキーを離した時にMOVE_SPEEDを歩く速度にする
MOVE_SPEED = SPEED
# -----------------------------------
else:
velocity.x = move_toward(velocity.x, 0, MOVE_SPEED) #SPEEDからMOVE_SPEEDに変更
velocity.z = move_toward(velocity.z, 0, MOVE_SPEED) #SPEEDからMOVE_SPEEDに変更
move_and_slide()