An example of code for an item moving left and rig...
# gamedev
o
An example of code for an item moving left and right between min and max positions. You don’t have to encode direction in a state etc. That’s trivial behavior, but imagine you want to do more complex stuff…
Copy code
while (true) {
                while (itemPosition.x < maxPosition) {
                    itemPosition += Vector(speed /* * dt */, 0)
                    nextFrame()
                }
                while (itemPosition.x > minPosition) {
                    itemPosition -= Vector(speed, 0)
                    nextFrame()
                }
            }