 Thread: Custom topdown movement problem.

1. Custom topdown movement problem.

So i tried making a custom 8-directional movement, the problem is with the diagonal movement. Up right and down left workes fine, but up left is much faster and down right is 2 times slower than up right.  Reply With Quote

2. Simplest way is to do a manual check if the key combinations to go diagonal is pressed and then cut the speed value in two.  Reply With Quote

3. Not really because the value isn`t two times the normal but something around 4/3 (up and left) and the other one 2/3 (down and right). Besides i mainly want to know why that happens.  Reply With Quote

4. Adding/removing to an object's X/Y position with a decimal point in Fusion always seems to round it "down" to a the lowest number.

(More accurately, it "floors". That means Floor(1.5) and Floor(1.9) both equal 1, but Floor(-1.5) 'rounds' down to -2.)

If you set an object's X position to X+1.5 every frame it will move exactly 1 pixel to the right every frame, but if you move it X-1.5 every frame it will move it 2 pixels to the left since it will floor down the value. The same goes for adding/subtracting to Y, it will always floor any integer you. Basically, the X/Y position is always an integer (no decimals) and not a float (can have decimals)

That means if you did want the object to accurately move diagonally at the correct speed using trig/Sqr decimal values, you can instead set aside some alterable values to store the "real" X/Y position as a float, and set the objects X/Y position to that value instead.

Here's a short example that I hope makes sense:
subpixel movement.mfa

The Blue object (Active 1, on the top) moves at 1.5 pixels per frame by adding to the X position. Moving left is faster than moving right as it floors -1.5 down to 2 when moving left, and floors 1.5 to 1 when moving right

The Red object (Active 2, in the middle) moves at -2 pixels left and -1 pixels right. Its speed is exactly the same as the blue object even though we're moving it by a different amount

The Pink (Magenta? Active 3, on the bottom) stores it's current X/Y position at the start of the frame and simply adds/removes 1.5 to that. Since it's an alterable value it can store decimals (which the object uses as it's X/Y position on screen) and moving left/right is the same speed  Reply With Quote

5. Marbenx, thanks for that, I was looking at the MFA above and couldn't figure out what was wrong, interesting to know that the rounding works that way. Cheers   Reply With Quote

6. You could alternatively set a "move angle" value that is whichever direction the player is holding (0 for right, 180 for left, etc) and base the player's velocity on cosine ( x = x*cos(angle), y = y*(0-sin(angle)) ).

If you want a quick fix, I believe multiplying your velocities by 0.717 is the most accurate number for diagonals.  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•