I'm creating a falling sand game and would like to implement velocity so elements can travel in different directions at varying speeds. Games such as Noita use this and it smoothens out the movement of the elements.
I have a 2d array and shift the elements around the 2d array to move them.
I've looked around and I can't find anything on this. I've gotten so far using line calculations but I'm curious as to the best method of handling this.
Another thing to consider is that if the velocity is small I still want to slowly move the elements. However if the velocity is 0.01 then it will always round down to zero and never move the element to another position.
My elements are stored in a 2d array so the calculated positions must always be integers.
Array
Element[] elements = new Element[1000][1000];
Element
class Element {
// Array position
int x, y;
Vector2 velocity = new Vector2();
public Element(int x, int y){
this.x = x;
this.y = y;
}
...
}
How can I implement velocity in a falling sand game?