# Thread: 8 direction motion bug

1. ## 8 direction motion bug

Here is a file with an object with movement in diagonal directions only. It acts differently in one diagonal direction than it does in another - I can't see why it should this. I'm hoping that I'm missing something. Anyone get the same problem?

I simplified the code to remove as much as possible. I took out all of the animation and made each direction have the same graphic with the same x and y point. I removed all of the buttons except for the ones that go diagonally - 7 = up and left for example. The problem still persists. If you toggle back and forth between the 7 and 3 directions, the ship goes at 45 degrees and stays in place. If you toggle back and forth between the 9 and 1 buttons, the ship does not go at 45 degrees and slowly moves up and to the right. The code is so simple at this point, it would seem to be some kid of bug.

Steve

2. ## Re: 8 direction motion bug

Could a few people at least verify that the object is indeed not moving at 45 degrees in one diagonal while it is in the other diagonal? This bug is really bothering me.
STeve

3. ## Re: 8 direction motion bug

I figured it out! =)

The built in position system doesn't have decimals, so you can only full pixel to position. If there are decimal values, they'll be rounded down. Alterable values support decimals. Here's a fixed version.

4. ## Re: 8 direction motion bug

Tomssuli,
I really appreciate you figuring this out.

But I'm still a bit confused about what is going on.

I set the speed to 5 and took either the sin or cos, so 5*sin 45 = 3.535 which was rounded down to 3. The % error between 3.535 and 3 is a whopping 15%, so that explains the possible error.

But, why does the error only happen in the 7 and 3 directions, and not in the 9 and 1 directions?

Steve

5. ## Re: 8 direction motion bug

I think it does have to do with the adding/substracting... If it always rounds down, then when substracted, 3.535 turns first into -3.535 and then is rounded down to -4... where added will be rounded down to 3. That causes certain directions go wrong.

For example: "Xcoord - 4px and Ycoord + 3px = not 45 degrees"

Of course "-4x & -4y = 45deg" as is "+3x & +3y"

That's what I think it's all about.

6. ## Re: 8 direction motion bug

Thanks again to Tomssuli for figuring this out. I have remade the homemade 8 direction widget and will upload in the widget up load section.

Steve

#### Posting Permissions

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