restructured folders
This commit is contained in:
parent
e3aec75404
commit
0f5045dc22
22 changed files with 32 additions and 21 deletions
89
entities/player/player.gd
Normal file
89
entities/player/player.gd
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
@onready var animated_mesh = $GobotSkin
|
||||
|
||||
var in_battle: bool = false
|
||||
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if in_battle == true:
|
||||
return
|
||||
|
||||
animated_mesh.idle()
|
||||
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
animated_mesh.fall()
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept"):
|
||||
print("jump")
|
||||
animated_mesh.run()
|
||||
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Camera rotation
|
||||
var camera_input_dir := Input.get_vector("joystick_right_left", "joystick_right_right", "joystick_right_left", "joystick_right_right")
|
||||
$CameraRoot.rotation.y += camera_input_dir.x
|
||||
|
||||
# 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("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
|
||||
if input_dir.length() > 0 and is_on_floor():
|
||||
animated_mesh.run()
|
||||
if input_dir.length() > 0 and not is_on_floor():
|
||||
animated_mesh.fall()
|
||||
|
||||
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
# Rotate the direction with the camera, so that the cameras forward direction
|
||||
# is the joysticks and the players forward direction
|
||||
direction = direction.rotated(Vector3.UP, $CameraRoot.rotation.y)
|
||||
|
||||
# Move character to the direction
|
||||
if direction.length() != 0:
|
||||
$GobotSkin.rotation.y = atan2(direction.x,direction.z)
|
||||
|
||||
if direction:
|
||||
velocity.x = direction.x * SPEED
|
||||
velocity.z = direction.z * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
if velocity.length() < 0.05:
|
||||
animated_mesh.idle()
|
||||
|
||||
# what happens when a battle starts?
|
||||
# the player is positioned (mostly somewhere else than the current position)
|
||||
# ui changes
|
||||
# music changes
|
||||
func start_battle(enemy: Node3D, player_position: Vector3) -> void:
|
||||
position = Vector3(player_position.x, position.y, player_position.z)
|
||||
in_battle = true
|
||||
velocity = Vector3.ZERO
|
||||
animated_mesh.idle()
|
||||
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
print("timer over")
|
||||
in_battle = false
|
||||
|
||||
func save() -> Dictionary:
|
||||
var save_dict = {
|
||||
"player_transform": {
|
||||
"pos_x": global_position.x,
|
||||
"pos_y": global_position.y,
|
||||
"pos_z": global_position.z,
|
||||
"rot_x": global_rotation.x,
|
||||
"rot_y": global_rotation.y,
|
||||
"rot_z": global_rotation.z
|
||||
}
|
||||
}
|
||||
return save_dict
|
||||
28
entities/player/player.tscn
Normal file
28
entities/player/player.tscn
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://be5bc5gjbo875"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_mv2yl"]
|
||||
[ext_resource type="PackedScene" uid="uid://cy36aygvs66pn" path="res://assets/models/gobot/gobot_skin.tscn" id="2_a4t6w"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_xuba7"]
|
||||
height = 1.7
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
axis_lock_angular_z = true
|
||||
script = ExtResource("1_mv2yl")
|
||||
|
||||
[node name="GobotSkin" parent="." instance=ExtResource("2_a4t6w")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0)
|
||||
shape = SubResource("CapsuleShape3D_xuba7")
|
||||
|
||||
[node name="CameraRoot" type="Node3D" parent="."]
|
||||
|
||||
[node name="SpringArm3D" type="SpringArm3D" parent="CameraRoot"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.64528, 2.83335)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="CameraRoot/SpringArm3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.965926, 0.258819, 0, -0.258819, 0.965926, 0, 0.0210915, 0.372644)
|
||||
Loading…
Add table
Add a link
Reference in a new issue