Hello, I got this movement function that was finished a few months back and it came to me that the “diagonal” movement is faster than the left,right,up,down. With my understanding it would be:
c^2 = a^2 + b^2
c^2 = (5)^2 + (5)^2
c = sqrt(25+25)
c = sqrt(50)
c = ~7
When I want them all to be 5 for example (while diagonal is actually moving 7!) when moving diagonal. Its registered to a circle “dpad” image on the screen. And I got a setLinearVelocity working with this function in my runtime and all that works fine np.
The movement part of the function:
if event.phase == "began" or event.phase == "moved" then local touchX = event.x - event.target.x local touchY = event.y - event.target.y if touchX \< -15 then velX = -5 sequence = "left" elseif touchX \> 15 then velX = 5 sequence = "right" else velX = 0 end if touchY \< -15 then velY = -5 sequence = "up" elseif touchY \> 15 then velY = 5 sequence = "down" else velY = 0 end
How would I go about to make it properly register the proper movement on the diagonal parts?
EDIT: The character already moves diagonal and everything I just want the math to match up to the same speed on every movement, I’m aware of the sprite only registers 4 ways and that is all working as intended.
Thanks for your time as always.