I’m making an Animal Crossing Style movement system for my character and have keyboard and controller support working.
I would like to change the speed relative to the power of the left stick (keyboard should be max power)
Heres the relevant code:
// Get the input direction
var inputDir = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
var sum = direction * SPEED;
// Finally, Move.
MoveAndCollide(sum);
I know you can get the strength of one using Input.GetActionStrength("Whatever") But I need to get it total. I could just get them all and add them together but that feels… wrong
You could consider remembering the highest absolute value to obtain the input speed. Normalize the vector to create a directional vector and multiply it by the speed, input speed, and delta.
code vith no godot lib
double x = 0.5;
double y = 0.5;
// Calculate the input speed
double inputSpeed = Math.Max(Math.Abs(x), Math.Abs(y));
// Calculate the magnitude of the vector
double c = Math.Sqrt(x * x + y * y);
// Normalize both x and y with respect to the magnitude c
x = x / c * inputSpeed;
y = y / c * inputSpeed;
So, I got rid of the multiplication, The player either moves at full speed or none, Is there a different function to move it that would allow for the slow movement?