I’m trying to follow this tutorial which uses GDScript but in C#.
In the final section
else:
# The player get to the next point
position = path[0]
path.remove(0)
# Update the distance to walk
distance_to_walk -= distance_to_next_point
That “path.remove(0)” I can’t seem to find in C#, it seems arrays are more limited in C# or I’m I doing something wrong. I have also tried to define my vector2 array as like
"Godot.Collections.Array< Vector2 > path " to access addtional methods such as remove, clear and such but that gives me conversion errors “Can’t convert between Godot Collections and Vector2D etc.” In other code.
But if I define a variable like ‘Vector2 path’ , it doesnt have the extra useful methods like remove, clear and such. Am I missing something?
I don’t use the C# version of Godot, but I’d expect C# Array object to have a RemoveAt(index) method that should be the equivalent of the mentioned gdscript code. That should remove an item from the array at the specified index.
Thank you JGodfrey, one of my problems if I use a C# array like that like "Godot.Collections.Array< Vector2D > " for example I get conversion errors asforementioned, maybe it’s something I’m misunderstanding?
You don’t just define a 2D Vector array just like Vector2D variableName?
AlMoeSharpton86 | 2020-06-21 20:37
Thanks again, that removeAt method was very helpful!
One of the nice things about using C# is that you are not limited to the types in GDScript. Have you tried using System.Collections.Generic.List<Vector2>?
Thank you, haven’t tried with Lists, I’ll try that!
AlMoeSharpton86 | 2020-06-22 15:31
Cannot implicitly convert type ‘System.Collections.Generic.List<Godot.Vector2>’ to ‘Godot.Vector2’ How would you solve this issue?
AlMoeSharpton86 | 2020-06-22 15:41
Thank you! Lists and types were the correct way to go, I used the method .ToArray to solve the conversion errors. Thank you