# Object's Y detection failure

Bugs will be moved here once resolved.

### » Wed Jun 18, 2014 6:16 am

The problem has nothing to do with C2 being unable to be pixel perfect. The problem is incorrect math. You're doing the calculations for only one of them and expecting them all to work. You placed all initial tiles at y positions -256, 0, 256, and 512 in the first example and -256, 0, and 256 in the second. By adding 8 to the y position each tick you will always get the y at 768. But the space between each tile, 256 pixels, is not divisible by 9, so the ones not at y=0 or wherever you are calculating from end up missing.

Do the math, watch the y position in the debugger or just repeatedly add 9 to 512 and watch what happens. It misses 774 and 770. It's not about either of those being divisible by 9, the problem is you're not starting from the same y position for all of the tiles, so they're offset. That's why one row works, and the others don't.

What you need is a different method. For example, you can check is the spawners are not overlapping any tiles, and if so, get the y position of the highest tile, then create a new row of tiles at that position-256.
Moderator
B
96
S
34
G
33
Posts: 3,007
Reputation: 27,921

### » Wed Jun 18, 2014 11:18 am

Arima wrote:The problem has nothing to do with C2 being unable to be pixel perfect. The problem is incorrect math. You're doing the calculations for only one of them and expecting them all to work. You placed all initial tiles at y positions -256, 0, 256, and 512 in the first example and -256, 0, and 256 in the second. By adding 8 to the y position each tick you will always get the y at 768. But the space between each tile, 256 pixels, is not divisible by 9, so the ones not at y=0 or wherever you are calculating from end up missing.

Do the math, watch the y position in the debugger or just repeatedly add 9 to 512 and watch what happens. It misses 774 and 770. It's not about either of those being divisible by 9, the problem is you're not starting from the same y position for all of the tiles, so they're offset. That's why one row works, and the others don't.

What you need is a different method. For example, you can check is the spawners are not overlapping any tiles, and if so, get the y position of the highest tile, then create a new row of tiles at that position-256.

Thanks I will try your stuff.
I was using a sprite trigger now though and have got the same gaps.
B
14
S
4
G
1
Posts: 241
Reputation: 1,749

### » Wed Jun 25, 2014 2:34 pm

Closing as not a bug. See 'Expecting math calculations to be exact' under Common mis-used events and gotchas. The errors occur at the CPU hardware level and affect all software on your computer, not just Construct 2.

The problem probably stems from the 'Move at angle' action, which calculates cos(angle) and sin(angle), which are often slightly imprecise. Even so the correct solution is to compare within a small range instead of expecting exact results. In fact your example does not use delta-time so is framerate dependent; even better is to use dt and a one-off action once it goes below a threshold.
Scirra Founder
B
414
S
245
G
92
Posts: 25,205
Reputation: 200,351

### » Wed Jun 25, 2014 10:37 pm

vagaev wrote:@Ashley

We can close this topic.
I realize I can't ask C2 to be pixel perfect.

The problem came from a delay between spawning the sprite and actually moving it. I accepted the fact that C2 can't handly such quick operations milliseconds perfect so I've come up with alternative solutions.

For those who might want to know. I just precreate 3 ranks of tiles and each time that for instance 3 blue collide with the sprite trigger i put those 3 new sprites in movement and immediately create 3 other sprites outside the layout ready to move.

For moving C2 does it very well.

hi
i see your description but i dont understand it well
can you send us .capx example ?
thanks
B
54
S
21
G
8
Posts: 875
Reputation: 9,197

### » Thu Jul 03, 2014 2:29 am

hi
can you post an .capx example to see how you solve this problem ?
thanks
B
54
S
21
G
8
Posts: 875
Reputation: 9,197

Previous