iAmMe
iAmMe

Reputation: 41

CS0019 Cannot multiply Vector2 and double

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

Answers (1)

Guru Stron
Guru Stron

Reputation: 141998

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:

Upvotes: 6

Related Questions