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

Jumping against and over a wall sometimes causes a collision that resets velocity (Arcade Physics) #2343

Closed
mattjennings opened this issue Jun 6, 2022 · 2 comments · Fixed by #2345
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior system:physics Related to the physics simulation including collision

Comments

@mattjennings
Copy link
Contributor

Kapture 2022-06-06 at 16 58 07

Steps to Reproduce

The above gif can be reproduced using this CodeSandbox example. (CodeSandbox is finicky with capturing key events, best to open the preview in a separate window).

Try moving the player to the right against the wall by holding the right arrow key. While still holding right, hit up to jump. Sometimes the player will slide along & above the wall, but other times it will "snap" to the top of the wall.

Expected Result

The player should slide along & above the wall

Actual Result

The player snaps to the top of the wall instead and velocity is reset - sometimes.

Environment

  • browsers and versions: Chrome 102, Safari 15.5
  • operating system: macOS 12.4
  • Excalibur versions: 0.26, 0.25, didn't try anything earlier
  • Using a macbook pro with 120hz screen incase that has an impact on the physics tick rate

Current Workaround

None that I know of. I'm still quite new to using Excalibur, but this movement logic was taken from the Sample Platformer, so let me know if there's a better way to be applying velocities/collisions that might remedy this.

@eonarheim
Copy link
Member

I mentioned in #2344 but I think these might be related.

I'm thinking a collision resolution bias towards vertical or horizontal collisions might help? Otherwise we may want to re-think the velocity solve step in the ArcadeSolver or perhaps make it configurable to be more forgiving on corner collisions such that if there is no clear correct vertical/horizontal direction to bias either horizontally or vertically.

image

@eonarheim eonarheim added bug This issue describes undesirable, incorrect, or unexpected behavior system:physics Related to the physics simulation including collision labels Jun 6, 2022
@eonarheim
Copy link
Member

Okay an additional tweak was made to fix this, effectively we don't adjust any velocities if the colliders are already moving away from the contact.

image

This makes platforms a bit more forgiving on corner when rolling off and jump up and around.

cancel-velocity-fix

eonarheim added a commit that referenced this issue Jun 10, 2022
…ores diverging contacts (#2345)

Closes #2344 #2343

This PR changes how the `ArcadeSolver` solves collisions to avoid errant collisions on seams in geometry. The idea behind this fix is to sort the collision contacts by distance. Additionally if a contact has no more overlap during processing they are now discarded so errant collisions are even evaluated.

Note there are no more left right collisions in the console compared to the [sandbox](https://8wf42u.csb.app/)
![sorted-collisions](https://user-images.githubusercontent.com/612071/172401390-9e9c3490-3566-47bf-b258-6a7da86a3464.gif)


This PR also fixes #2343 by ignoring "divergent contacts" which are when the underlying body's are already moving away from the contact, so no velocity adjustment is needed. This was noticeable when clipping corners, but the object was already moving out of the collision.

![cancel-velocity-fix](https://user-images.githubusercontent.com/612071/172500318-539f3a36-31ae-4efc-b6ab-c4524b297adb.gif)


TODO: 
* [x] Look into #2343 to see if this helps
* [x] Also sort by collider proximity
* [x] Tests

## Changes:

- Change the `Solver` from abstract class to an interface to be more flexible about solvers
- Sorts contacts by body distance from each other
- Cancels "divergent contacts" when the bodies are moving away from the contact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior system:physics Related to the physics simulation including collision
Projects
None yet
2 participants