Added debug labels
This commit is contained in:
@ -1,34 +1,2 @@
|
||||
class_name Player
|
||||
extends CharacterBody3D
|
||||
|
||||
const MOVE_SPEED = 4.5
|
||||
const JUMP_VELOCITY = 4.5
|
||||
const DECELERATE = 0.75
|
||||
|
||||
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()
|
||||
|
||||
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
|
||||
extends Character
|
||||
|
@ -1,23 +1,34 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"]
|
||||
[ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://character/HealthComponent.tscn" id="2_np5ag"]
|
||||
[ext_resource type="Script" path="res://player/PlayerController.gd" id="3_oox5k"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_fx2di"]
|
||||
[sub_resource type="PrismMesh" id="PrismMesh_y7abh"]
|
||||
size = Vector3(0.5, 1.6, 0.5)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5eict"]
|
||||
diffuse_mode = 3
|
||||
albedo_color = Color(0.0588235, 0.0823529, 0.113725, 1)
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"]
|
||||
radius = 0.23
|
||||
height = 1.6
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_8125v"]
|
||||
material = SubResource("StandardMaterial3D_5eict")
|
||||
|
||||
[node name="Player" type="CharacterBody3D" groups=["Player"]]
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("model") groups=["player"]]
|
||||
script = ExtResource("1_8gebs")
|
||||
model = NodePath("Model")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
shape = SubResource("BoxShape3D_fx2di")
|
||||
[node name="Model" type="Node3D" parent="."]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
mesh = SubResource("BoxMesh_8125v")
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Model"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)
|
||||
mesh = SubResource("PrismMesh_y7abh")
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)
|
||||
shape = SubResource("CapsuleShape3D_2f50n")
|
||||
|
||||
[node name="HealthComponent" parent="." instance=ExtResource("2_np5ag")]
|
||||
|
||||
[node name="PlayerController" type="Node" parent="." node_paths=PackedStringArray("character")]
|
||||
script = ExtResource("3_oox5k")
|
||||
character = NodePath("..")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
|
20
player/PlayerController.gd
Normal file
20
player/PlayerController.gd
Normal file
@ -0,0 +1,20 @@
|
||||
class_name PlayerController
|
||||
extends CharacterController
|
||||
|
||||
@export var character: Character
|
||||
var move: Vector2
|
||||
|
||||
func _input(_event):
|
||||
move = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
character.direction = (Global.camera.transform.basis * Vector3(move.x, 0, move.y))
|
||||
character.direction.y = 0
|
||||
character.direction = character.direction.normalized()
|
||||
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
character.jump()
|
||||
|
||||
if Input.is_action_just_pressed("dash"):
|
||||
character.dash()
|
||||
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
character.attack()
|
Reference in New Issue
Block a user