Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 04:21:31 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Unity physics based platformer..
Pages: [1]
Print
Author Topic: Unity physics based platformer..  (Read 2614 times)
indie11
Level 2
**


View Profile
« on: November 01, 2015, 04:46:37 AM »

I've been messing around with the Unity physics platformer example and straight outta no where I am facing the famous "edge case" issue


I've already got a custom controller working that uses the raycast approach. I want to use rope bridges and other components that heavily depend on the physics system.. writing custom physics and getting it to work properly will require a lot of effort.
I'd really like to know if anyone here fixed the "edge case" problem or rolled out a custom controller using 2d physics
Logged

zilluss
Level 1
*



View Profile
« Reply #1 on: November 04, 2015, 05:43:41 AM »

If you don't have slopes, you can simply apply a small impulse everytime the bottom parts of the player-body touch a terrain-body. If you do have slopes you need to check on that obviously.
Logged

@zilluss | Devlog  Hand Point Right
Zorg
Level 9
****



View Profile
« Reply #2 on: November 04, 2015, 05:55:59 AM »

What happens in the moment you are stuck there? From the image i would expect that the character slips off the edge.
Logged
indie11
Level 2
**


View Profile
« Reply #3 on: November 05, 2015, 02:35:06 AM »

If you don't have slopes, you can simply apply a small impulse everytime the bottom parts of the player-body touch a terrain-body. If you do have slopes you need to check on that obviously.

Slopes and all kind of shapes.. the circle collider works well when there are no hard edged platforms..

What happens in the moment you are stuck there? From the image i would expect that the character slips off the edge.

Visually the player appears to be in air.. player can't move forward in the "stuck direction".. character slips off the edge only in case of a round platform
Logged

oahda
Level 10
*****



View Profile
« Reply #4 on: November 05, 2015, 03:02:21 AM »

Would it be possible simply to make the capsule less wide but the same height without it messing with other cases too much? As in a bit narrower than the sprite to avoid having it look like the character is stuck in mid-air?

Otherwise perhaps some raycasting or something might help you figure out whether you're on an edge so that you can do something about it...
Logged

zilluss
Level 1
*



View Profile
« Reply #5 on: November 05, 2015, 07:43:08 AM »

I have 3 suggestions you might try:

1) Make rounded corners. The player will slip off the corner, since it's not a hard edge anymore. Instead of a rounded corner it might be sufficient to make a slightly angled ledge. The next problem will be to get the ledge right so it doesn't look weird when the player slips off or stands ath the edge.

2) Decrease the friction of your player or the underground. You can also make a special collider for the edge that has a decreased friction so the overall movement physics don't change.

3) What I suggested in my first answer. Use OnCollisionStay2D to get the collission event with the terrain. Since the event contains both colliders and their contact points it'll be easy to find out when the player is touched by an edge and you can unstuck it with an impulse.
Logged

@zilluss | Devlog  Hand Point Right
Eendhoorn
Level 6
*

Quak


View Profile
« Reply #6 on: November 05, 2015, 08:51:51 PM »

Set friction on all physics materials to 0 and apply your own friction in an update call every frame.
Logged

Trent
Level 0
***


Someday I'll make games!


View Profile WWW
« Reply #7 on: November 16, 2015, 02:30:35 PM »

The inner edge issue is often seen in many box2d driven platformers. None of the fixes I've seen around the web seem to work if you are using tiles with a lot of overlapping edges.

Stuff like 0 friction helps movement, but does nothing to keep you from getting caught on edges.

A narrower capsule also won't stop you from getting stuck.

Ive seen the suggestion to add circles on the corners of boxes to get rounded collision but that just adds more edges to get caught on.

And using a circle for everything is also impractical. Also, high velocity collisions with the circle collider and a tile floor with tons of snagpoints often sends the circle collider flying in the air.

Platformer physics with box2d is always pretty buggy to some extent. I've always prefered to write a simple AABB collision system, but with slopes and the rope bridge, its obvious that another fix needs to be found.

The closest fix I've found is to use the edge collider on the bottom of your character. The world scale also seemed to have some effects.



The "ski" has 0 friction and doesn't seem to get caught nearly as often as I expected. There are STILL edge cases, but they are much less frequent for me this way. When someone comes up with the ultimate solution, I'm ready!

EDIT: Another physics option is the iterations per frame, which is controlled in Edit > Project Settings > Time
Logged

Mr Speaker
Level 0
***

Mr Speaker: @mrspeaker


View Profile WWW
« Reply #8 on: November 17, 2015, 08:23:59 AM »

Great tips Trent - thanks!
Logged
zilluss
Level 1
*



View Profile
« Reply #9 on: November 19, 2015, 05:03:48 AM »

The inner edge issue is often seen in many box2d driven platformers.

Are you talking about edges between ground tiles? You can fix them with ghost vertices. That's what they're for and they work really well from my experience. A problem with a rectangular player shape is that handling slopes is trickier than with a capsule. If you don't have slopes, you can just set friction to zero and control the velocity manually with impulses (which gives you a tighter control over acceleration/decceleration as well).

Yet another solution is a seperate circle, attached with a revolute joint to a rectangle. It enables you to stay on slopes by fixing the wheels rotation. I should write this stuff down some day  Durr...?
Logged

@zilluss | Devlog  Hand Point Right
DazeHill
Level 0
*


View Profile
« Reply #10 on: November 23, 2015, 05:37:26 PM »

Hello, might I interest you in my platforming module right here?

http://forums.tigsource.com/index.php?topic=51596.0

It uses Unity's Box2D implementation, and seems to address most if not all the cases discussed in this thread.

The thread will lead to an article conceptually explaining the issues, then you can download the source code to specifically know how everything is done, or you can simply use it as-is if you find it more convenient.

Hope I am of some help!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic