Reputation: 41
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)
Upvotes: 3
Views: 1712
Reputation: 141998
Documentation does not list Vector2
multiplication operator accepting double
. Try using float
s (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:
Upvotes: 6