Refactored input logic out of grunkbeast controller

This commit is contained in:
Rob Kelly 2025-04-10 20:00:17 -06:00
parent 0c10a95cbf
commit 2b721b1a1c
4 changed files with 28 additions and 6 deletions

View File

@ -0,0 +1,10 @@
extends Node3D
@onready var grunk_beast: GrunkBeast = %GrunkBeast
func _process(_delta: float) -> void:
# Control grunkbeast movement
grunk_beast.move(
Input.get_axis("move_back", "move_forward"), Input.get_axis("move_right", "move_left")
)

View File

@ -0,0 +1 @@
uid://b1tbovuphat7d

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=11 format=3 uid="uid://cbxlfnlmgdvsq"]
[gd_scene load_steps=12 format=3 uid="uid://cbxlfnlmgdvsq"]
[ext_resource type="PackedScene" uid="uid://d2664rpg4losx" path="res://src/world/grunk_beast/grunk_beast.tscn" id="1_6yv42"]
[ext_resource type="Script" uid="uid://bukihqt1lybnx" path="res://src/util/frame_skipper.gd" id="1_eco5q"]
[ext_resource type="Script" uid="uid://b1tbovuphat7d" path="res://levels/grunkbeast_test/grunkbeast_test.gd" id="1_ovhaj"]
[ext_resource type="Script" uid="uid://cpt8dy0csa3eu" path="res://levels/grunkbeast_test/fixed_camera.gd" id="2_77sam"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_goufh"]
@ -28,6 +29,7 @@ height = 1.0
radius = 2.0
[node name="GrunkbeastTest" type="Node3D"]
script = ExtResource("1_ovhaj")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.866025, -0.156955, -0.474726, 0.5, 0.271854, 0.82225, 0, -0.949453, 0.31391, 0, 0, 0)
@ -58,6 +60,7 @@ script = ExtResource("1_eco5q")
frame_skip = 3
[node name="GrunkBeast" parent="FrameSkipper" instance=ExtResource("1_6yv42")]
unique_name_in_owner = true
move_speed = 8.0
step_time = 0.06

View File

@ -1,6 +1,7 @@
class_name GrunkBeast extends Node3D
## The nefarious grunkbeest!
##
## Uses tank controls.
## Procedural animation adapted from https://github.com/CBerry22/Godot-4.0-Procedural-Animation
@export var move_speed := 6.0
@ -13,12 +14,20 @@ class_name GrunkBeast extends Node3D
@export var step_distance := 1.0
@export var step_target_offset := 10.0
var _forward := 0.0
var _theta := 0.0
@onready var target_fl: BeastIKTarget = $Armature/TargetFL
@onready var target_fr: BeastIKTarget = $Armature/TargetFR
@onready var target_bl: BeastIKTarget = $Armature/TargetBL
@onready var target_br: BeastIKTarget = $Armature/TargetBR
func move(forward: float, theta: float) -> void:
_forward = forward
_theta = theta
func _process(delta: float) -> void:
# Reorient based on relative leg position
var p1 := Plane(target_bl.global_position, target_fl.global_position, target_fr.global_position)
@ -38,8 +47,7 @@ func _process(delta: float) -> void:
position = position.lerp(position + basis.y * distance, move_speed * delta)
# Movement
var direction := Input.get_axis("ui_down", "ui_up")
translate(Vector3(0, 0, direction) * move_speed * delta)
var a_direction := Input.get_axis("ui_right", "ui_left")
rotate_object_local(Vector3.UP, a_direction * turn_speed * delta)
translate(Vector3.BACK * _forward * move_speed * delta)
rotate_object_local(Vector3.UP, _theta * turn_speed * delta)
_forward = 0.0
_theta = 0.0