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

[2D physics] Random flipping of sprite when rotated. #25759

Open
Tracked by #45334
Sslaxx opened this issue Feb 10, 2019 · 3 comments
Open
Tracked by #45334

[2D physics] Random flipping of sprite when rotated. #25759

Sslaxx opened this issue Feb 10, 2019 · 3 comments

Comments

@Sslaxx
Copy link

Sslaxx commented Feb 10, 2019

Godot version:
3.1 beta3.

OS/device including version:
Linux 64-bit. Unlikely to be different under another OS.

Issue description:
The player sprite uses a Raycast2D to detect the angle of the floor underneath it (PlayerPivot). It also has this code:

(to disable when in the air):

	if ($PlayerPivot.enabled):	# If in the air and the pivot/floor edge detectors are enabled, disable them.
		$PlayerPivot.enabled = false
		$FloorEdgeLeft.enabled = false
		$FloorEdgeRight.enabled = false
		rotation = 0			# Avoid the player character being at odd angles when in the air and returning to the ground.

(to enable when on the floor, and check/change rotation angle):

	if (!$"PlayerPivot".enabled):	# If on the ground and the pivot/floor edge detectors are not enabled, enable them.
		$"PlayerPivot".enabled = true
		$"FloorEdgeLeft".enabled = true
		$"FloorEdgeRight".enabled = true
	else:							# Make sure the player is angled to the ground.
		ground_normal = $"PlayerPivot".get_collision_normal ()
		ground_angle = (floor_normal.angle_to (ground_normal))
		rotation = (rotation if player_speed < 0.05 else ground_angle)

This usually works as expected - the player sprite "follows" the angle of the floor underneath it. But sometimes, for reasons not entirely clear, sometimes the sprite will flip (usually by 90 degrees, but I've noticed other angles too). It seems to do this especially when having stopped mid-way on a slope and started to run up or down it, or running off the end of a slope and landing on a higher platform. This appears to be completely at random and is not reliably reproducible as far as I have determined.

I am looking at using the collision info for the player sprite's collision shape directly instead of a Raycast, but I'm not sure if I'd still run into the same problem. I'm also not 100% sure this isn't my error.

Minimal reproduction project:
Sslaxx/Sonic_Outbreak@1ab26ed (https://github.com/Sslaxx/Sonic_Outbreak/tree/godot_sonic_engine)

Sslaxx added a commit to Sslaxx/Sonic_Outbreak that referenced this issue Feb 10, 2019
Lots of sanity checking is likely to be needed before more of the issues
that are happening entirely at random (seemingly) can be fixed. There may
be Godot bugs involved.

godotengine/godot#25759

Prevented super-powered jumping (I think) that can sometimes happen by
jumping when running up a slope (or if velocity.y is non-zero).

Signed-off-by: Stuart "Sslaxx" Moore <[email protected]>
@ghost
Copy link

ghost commented Feb 11, 2019

If you're not having any issues with the vector signs juggling for a frame, then it could be related to this: #21020

I had issues with sprites when dealing with rotation and trying to use (-1, 1) scaling for mirroring. It doesn't seem to return what you would expect with certain rotations when you have inverted scaling.

@Sslaxx
Copy link
Author

Sslaxx commented Feb 11, 2019

I hadn't noticed, but I'll see if I can do any more testing to find out.

@Sslaxx
Copy link
Author

Sslaxx commented Jul 21, 2020

So far, using the version of Sonic Outbreak (the project I reported this issue as happening in) from #24050 (comment) with 3.2.2 I haven't noticed this issue.

I have noticed that jumping when moving no longer triggers the appropriate animation (when it did before) and incorrect jumping distances/speeds. Unsure at this stage if it's a bug in my code exposed by 3.2.2 (more likely), or a bug in 3.2.2.

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