Take a look at this with console open.
why the Ys are float numbers? shouldn’t they be just integers? in a game I’m working on i need to compare Ys and check if they are same, I could just round them somehow but I was wondering if there is a cleaner way? or maybe I’m doing something wrong that cause this?
one more question: How can I make those cubes reach 100% of their velocity in no time? I tried to change their body.acceleration.y but nothing changed
Thanks
In JavaScript, there fundamentally are no integers, only floats. I don’t immediately see anything wrong with rounding them to compare them, but I’d recommend Math.floor or Math.ceil so you don’t get problems if a coordinates ends up being closer to a higher or lower integer. If you’re only comparing two numbers, you could also subtract them and check if the result is less than a given threshold (such as 0.001).
As for your second question, acceleration denotes the change of the body’s speed over time, so they’ll gradually reach the desired velocity. If I’m understanding your question correctly, you can instead try directly setting the body.velocity (or use the body.setVelocity(x, y) / body.setVelocityX(x) / body.setVelocityY(y) methods since they update some other properties, too).