How do I use Vector2.ZERO?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By krokoloko

I’m writing a PlayerMovement script and want to set the move direction variable to a zero vector and saw in the documentation that the Vector2 class contains constants that would allow me to simply use that instead of setting the move direction to a new Vector2(0, 0).

This is the code that where I want to se the move direction to a zero vector.

public void Update(float delta)
{
	switch(state)
	{
		case MOVEMENT_STATE.NONE:
			break;
		case MOVEMENT_STATE.MOVING:
			accumalative = MIN(accumalative+delta, acceleration_time);
			break;
		case MOVEMENT_STATE.MOVE_STOP:
			accumalative = MAX(accumalative-delta, 0);
			if(accumalative <= 0)
			{
				move_direction = Vector2.ZERO;
				state = MOVEMENT_STATE.NONE;
			}
			break;
		default:
			break;
	}		
}	

And this is the error the compiler gives me.

PlayerMovement.cs(82,31): ‘Vector2’ does not contain a definition for ‘ZERO’.

Would appreciate it if someone could show me how it’s done (I’m pretty rusty with c# scripting after I made my switch to c++).

:bust_in_silhouette: Reply From: jgodfrey

For the C# api, I think that’s Vector2.Zero (notice the character case). Unofficial API docs here:

https://paulloz.github.io/godot-csharp-api/3.5/Godot.Vector2.html?q=vector2

Ohhh that makes sense, thank you also for sharing the API docs. Much appreciated

krokoloko | 2023-02-20 17:18