Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision with Grid and Hitbox is off by a pixel when the Hitbox's entity has non-integer x and y values. #607

Open
TaylorAnderson opened this issue Sep 2, 2018 · 1 comment

Comments

@TaylorAnderson
Copy link

TaylorAnderson commented Sep 2, 2018

  • HaxePunk version: 4.0.1
  • Target(s): At least Windows, Neko, and HTML5, but I suspect all platforms
  • Haxe version: 3.4.7
  • OpenFL/Lime or NME version: OpenFL 8.0.0, Lime 6.3.0

I'm noticing an issue where if I have a simple piece of code like

		if (collide("level", x, y) == null) {
			this.y ++;
		}

The result is that the Entity will travel one pixel into the grid, vertically. I haven't fully tested but I'm fairly certain this also happens on the x axis as well.

This seems to only happen when the Entity's y value is a non-integer.

I tried finding a solution for this but I couldn't seem to find where the problem was. Hopefully someone here has better luck.

Thanks,
Taylor Anderson.

@XANOZOID
Copy link
Member

This was also the case in another engine I used to use, but the solution wasn't to fix their engine it was actually to just ceil or floor the positions you're using in the collision function.

The problem is somewhat in your control as well . . . this may be more of a feature request rather than a bug. . .

The second problem is that both instances can have decimal locations, so that causes more precision problems to work with. In most cases you'll know how you want the interactions to happen and understand what instances move in non-integer increments, so you should try to work with that in mind. It would be much harder for us to generalize the common precision problem in programming since its not a problem for every game.

I recommend something like this:

if( collide("level", x, y) == null ){
	this.y ++;
}

// offset gaurd  
y = Math.round( y );
if( collide("level", x, y ) != null ){
	this.y --;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants