From 3d4e8bd6195de360b405b89d58231bc8a3d3a475 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Fri, 22 Aug 2025 13:10:53 -0600 Subject: [PATCH] inheritance is hard --- .../Entities/Characters/Movers/pedal.gd | 27 +++++++++---------- .../Characters/Players/Kobolds/Baby/baby.gd | 2 +- .../Entities/Characters/Players/player.gd | 12 ++++----- .../Entities/Characters/character.gd | 13 ++++++--- .../mvp-walk-with-collision/icon.svg.import | 0 .../mvp-walk-with-collision/project.godot | 0 Examples/mvp-walk-with-collision/root.tscn | 0 7 files changed, 29 insertions(+), 25 deletions(-) mode change 100755 => 100644 Examples/mvp-walk-with-collision/Entities/Characters/Movers/pedal.gd mode change 100755 => 100644 Examples/mvp-walk-with-collision/Entities/Characters/Players/Kobolds/Baby/baby.gd mode change 100755 => 100644 Examples/mvp-walk-with-collision/Entities/Characters/Players/player.gd mode change 100755 => 100644 Examples/mvp-walk-with-collision/Entities/Characters/character.gd mode change 100755 => 100644 Examples/mvp-walk-with-collision/icon.svg.import mode change 100755 => 100644 Examples/mvp-walk-with-collision/project.godot mode change 100755 => 100644 Examples/mvp-walk-with-collision/root.tscn diff --git a/Examples/mvp-walk-with-collision/Entities/Characters/Movers/pedal.gd b/Examples/mvp-walk-with-collision/Entities/Characters/Movers/pedal.gd old mode 100755 new mode 100644 index 94b7e04..c61d4d3 --- a/Examples/mvp-walk-with-collision/Entities/Characters/Movers/pedal.gd +++ b/Examples/mvp-walk-with-collision/Entities/Characters/Movers/pedal.gd @@ -1,12 +1,12 @@ extends Node -var speed = 1 +var speed = 1.0 -func to_move_rotate(delta: float): +func to_move_rotate(global_transform, delta: float): var mv = Vector3.ZERO - var rot = Vector3.ZERO + var rot = 0.0 for state in _states(): - var duo = _duo_for_state(delta, state) + var duo = _duo_for_state(global_transform, delta, state) mv += duo[0] rot += duo[1] return [mv, rot] @@ -64,8 +64,9 @@ func _states_turning(): return [STATE_TURNING_RIGHT] return [] -func _duo_for_state(delta: float, state): +func _duo_for_state(global_transform, delta: float, state): var direction = Vector2.ZERO + var rotation = 0.0 match state: STATE_MOVING_FORWARD: direction.y = -1 @@ -76,23 +77,21 @@ func _duo_for_state(delta: float, state): STATE_MOVING_RIGHT: direction.x = 1 STATE_TURNING_LEFT: - pass - rotate_object_local(Vector3.UP, speed * delta) + rotation = speed * delta STATE_TURNING_RIGHT: - pass - rotate_object_local(Vector3.UP, -speed * delta) + rotation = -speed * delta STATE_IDLE: pass if direction == Vector2.ZERO: - return [Vector3.ZERO, Vector3.ZERO] + return [Vector3.ZERO, rotation] direction = direction.normalized() var forward = global_transform.basis.z var right = global_transform.basis.x var relative_direction = (forward * direction.y + right * direction.x) - relative_direction.x *= speed - relative_direction.z *= speed - relative_direction.y = -speed + relative_direction.x *= speed * delta + relative_direction.z *= speed * delta + #relative_direction.y = -speed - return [relative_direction, Vector3.ZERO] + return [relative_direction, rotation] diff --git a/Examples/mvp-walk-with-collision/Entities/Characters/Players/Kobolds/Baby/baby.gd b/Examples/mvp-walk-with-collision/Entities/Characters/Players/Kobolds/Baby/baby.gd old mode 100755 new mode 100644 index 3d78078..a7edd45 --- a/Examples/mvp-walk-with-collision/Entities/Characters/Players/Kobolds/Baby/baby.gd +++ b/Examples/mvp-walk-with-collision/Entities/Characters/Players/Kobolds/Baby/baby.gd @@ -1,4 +1,4 @@ extends "res://Entities/Characters/Players/Kobolds/kobold.gd" func _ready(): - mover.speed = 3 + self.mover.speed = 1.5 diff --git a/Examples/mvp-walk-with-collision/Entities/Characters/Players/player.gd b/Examples/mvp-walk-with-collision/Entities/Characters/Players/player.gd old mode 100755 new mode 100644 index f4fe491..f776cde --- a/Examples/mvp-walk-with-collision/Entities/Characters/Players/player.gd +++ b/Examples/mvp-walk-with-collision/Entities/Characters/Players/player.gd @@ -4,14 +4,14 @@ func _input(event): if event is InputEventKey: match event.keycode: KEY_W: - self.state_move_forward = event.pressed + self.mover.state_move_forward = event.pressed KEY_A: - self.state_move_left = event.pressed + self.mover.state_move_left = event.pressed KEY_S: - self.state_move_backward = event.pressed + self.mover.state_move_backward = event.pressed KEY_D: - self.state_move_right = event.pressed + self.mover.state_move_right = event.pressed KEY_Q: - self.state_turn_left = event.pressed + self.mover.state_turn_left = event.pressed KEY_E: - self.state_turn_right = event.pressed + self.mover.state_turn_right = event.pressed diff --git a/Examples/mvp-walk-with-collision/Entities/Characters/character.gd b/Examples/mvp-walk-with-collision/Entities/Characters/character.gd old mode 100755 new mode 100644 index 50d4509..9e9a37a --- a/Examples/mvp-walk-with-collision/Entities/Characters/character.gd +++ b/Examples/mvp-walk-with-collision/Entities/Characters/character.gd @@ -1,8 +1,13 @@ extends PhysicsBody3D -var mover = new("res://Entities/Characters/Movers/pedal.gd") +var mover := preload("res://Entities/Characters/Movers/pedal.gd").new() func _physics_process(delta: float): - duo = self.mover.to_move_rotate(delta) - velocity = duo[0] - move_and_slide() + var duo = self.mover.to_move_rotate(self.global_transform, delta) + self._physics_process_with(duo[0], duo[1]) + +func _physics_process_with(vel, rot): + self.velocity = vel + self.rotate_object_local(Vector3.UP, rot) + print("vel", vel) + self.move_and_collide(self.velocity) diff --git a/Examples/mvp-walk-with-collision/icon.svg.import b/Examples/mvp-walk-with-collision/icon.svg.import old mode 100755 new mode 100644 diff --git a/Examples/mvp-walk-with-collision/project.godot b/Examples/mvp-walk-with-collision/project.godot old mode 100755 new mode 100644 diff --git a/Examples/mvp-walk-with-collision/root.tscn b/Examples/mvp-walk-with-collision/root.tscn old mode 100755 new mode 100644