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

Smooth diagonal movement requires global_position to be rounded or floored #26291

Open
girng opened this issue Feb 26, 2019 · 2 comments
Open

Comments

@girng
Copy link

girng commented Feb 26, 2019

Godot version:
51c1d55

OS/device including version:
Windows 10, GTX 950

Prelude:
I spent the last couple days isolating this and finally found a solution. I was thinking of not making a bug report because it might be an edge case, but I feel like it's important enough. And other Godot developers might be affected by it.

Issue description:
When moving with diagonal movement, round() must be used if the player's global_position is an even number, and floor() must be used if the player's global_position is an odd number. Otherwise, diagonal movement will cause jitter. This also happens using Camera2D, but I chose custom_transform to show what happens with and without .round().

Minimal reproduction project:
SmoothDiagonalMovementBug.zip

Ways to remove the diagonal movement jitter:

  • Remove.round() from transform2[2].
  • New Problem: When the character is moving, white/black lines will flicker all over the tilemap. The developer can partially fix this by disabling the filter property for that specific tileset texture.
  • Next New Problem: Now, when the above is done, the lines will appear sporadically, not all the time.

  • Project Settings -> Rendering -> Quality -> Enable "Use Pixel Snap"
  • New Problem: Diagonal movement is smooth, but sprites being modified by the AnimationPlayer now become distorted/not smooth (for example, using a animated character like gBot)

  • Remove normalized() from char_direction
  • New Problem: Diagonal movement now becomes faster than horizontal movement (entire point of normalized() is to achieve the same speed.

The solution to get everything working smoothly is around line 34, in player.gd:

	if is_diagonal && gg.diagonal_fix == true:
		# Even
		if speed % 2 == 0:
			global_position = global_position.round()
		else: # Odd
			global_position = global_position.floor()

I might have forgot another way that makes the diagonal movement smooth which has weird side effects; but I think this is sufficient. Thanks for taking a look!

@girng
Copy link
Author

girng commented Feb 27, 2019

Did some more testing. Checking for diagonal movement to use floor or round is irrelevant. Just simply using round() removes the jitter

@clayjohn
Copy link
Member

@girng Can this be closed?

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

No branches or pull requests

2 participants