I am using C# and Godot.
I have been able to multiple Vector2 and float but the movement of the character does not work when delta is a float.
direction is a Vector2 and both speed and delta are double.
Here is my code:
Velocity = direction.Normalized() * speed * delta;
The line of code results in CS0019 error stating that operator '*' cannot be applied to operands of type 'Vector2' and 'double'.
I am unable to change speed and delta into a float because if delta is a float, _PhysicsProcess cannot be overridden and does not move the character:
public override void _PhysicsProcess(double delta)
Documentation does not list Vector2 multiplication operator accepting double. Try using floats (via casting):
Velocity = direction.Normalized() * (float)(speed * delta);
Or just declare speed and delta as floats from the start.
Note that his cast is not lossless (i.e. not every double can be correctly converted to float).
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With