How do I make pixel perfect collisions?

Get help using Construct 2

Post » Sun Sep 23, 2012 5:28 am

For my side scrolling game, I'm using an invisible rectangle for collision detection. I pin my main sprite to the location of the rectangle which is updated "every tick". When the main sprite jumps on solid tiles, the collision detection works perfectly about 50% of the time. But half the time, the sprite will sink 1 pixel into the ground.

Because my game is low resolution (screen 256, 240) and my main sprite is only 29x30, a single pixel off is noticeable. I've verified that the Y coordinate is the same regardless of whether the sprite appears to be "on the ground" like normal or "sunken into the ground".

Any ideas? Or is pixel perfection just not plausible? I could always multiply everything in my game by a factor of 4 for example so that the sinking in would only appear to be 1/4th the depth of a pixel but I'd rather fix the problem than mask it.
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Sun Sep 23, 2012 5:44 pm

I think that the 1 px error is a render problem, or the engine has to aproximate a distance < 1px, and that's why. If you show us a bit of your code maybe we can be more specific.
B
15
S
3
G
2
Posts: 42
Reputation: 2,412

Post » Sun Sep 23, 2012 6:05 pm

There are a few reasons this happens. An easy fix is to check if the player is both on the floor and overlapping a collision tile. If so, move the player up one pixel.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Sun Sep 23, 2012 6:05 pm

I examined the example that comes with Construct 2 "Platform 1, Simple Movement" and I see it has the same 1 pixel error. So I have to assume it's just a fundamental flaw in the system. My code is nothing special. Just a jumping box for a sprite that is my main character and some solid sprites to jump on.
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Sun Sep 23, 2012 6:06 pm

Tokinsom, I'll try messing with those two thing. I already verified that my sprite is at the same Y position regardless of whether it is on the floor or sunken into the floor.
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Mon Sep 24, 2012 3:30 pm

Have you tried turning pixel rounding on on the project properties? ;]
B
38
S
8
G
3
Posts: 438
Reputation: 6,869

Post » Mon Sep 24, 2012 5:39 pm

It's not pixel rounding issue, it's the way C2 platform behavior works. Many people have noticed this before.
Read this, this, and this.

Your only solution is custom platform engine with loops, becouse C2 is against the old school , but thats not so hard to pulloff and most of all with custom platform engine you can have variable jumps

in this you never hit ceiling (pixel rounding On)podpathos2012-09-24 17:44:20
B
12
S
2
G
2
Posts: 96
Reputation: 1,583


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Artpunk, indiegrimes, NRABrazil, PixelatedTrip, WhosWho and 26 guests