Godot Version 4.7.1
Question
I want an entities movement speed to be affected by their Speed stat.
I’ve been following a tutorial on using a state machine for character movement and I want each movement state to call the same speed stat since if I want to apply buffs and debuffs, different entities have different speed stats, etc. I will need them all to call the same thing
For example
extends CharacterBody3D
@export var speed_stat: float = 10
So the stat is stored in the character body for now might make a node with it in separate as I also want some other stats. This is the root of the tree.
extends State
class_name Motion
const BASE_SPEED: float = 5
Motion stores various constants and the programming for the velocity and other things. I’m not sure about having this call the speed stat as I would ideally keep this dedicated to just that.
State just has functions in
extends Motion
func _update(_delta: float) -> void:
_set_direction()
_calculate_velocity(BASE_SPEED*(1+((speed_stat-10)/100)),direction,_delta)
I just want to get that variable speed stat into each of the movement states so that when in game they’re adjusted (character creation, equipment, levels, buffs/debuffs) it can do the calculations appropriately.
I’ve looked at tutorials for stat systems but they have it so that stats are resources and most focus on health and for some reason when they use a different word I can’t wrap my head around it. I thought it would be as simple as just having the export variable in the character 3D body but when doing it as I’ve done above “Identifier “speed_stat” not declared in the current scope.”
I have asked a similar question before but I still can’t wrap my head around the specific thing I need to do to get this variable to be seen further down the tree