Hello Guest

Author Topic: Colider penetration  (Read 11721 times)

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Colider penetration
« on: July 24, 2012, 12:37:16 pm »
hi,

my character (a 2d sprite) can walk right / left.

when he hits a wall and keep walking against it, the two colliders (character & wall) seems to interpenetrate a little bit thus creating a jaggy effect of back and forth for the 2d sprite.

is there way to avoid this ? is there a threshold that i could change somewhere ?

thanks,

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Colider penetration
« Reply #1 on: July 24, 2012, 12:49:47 pm »
The penetration threshold is in
Edit > Project Settings > Physics

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #2 on: July 24, 2012, 01:08:46 pm »
yes, i've already decreased to a 0.00001 value but still, there's a friction on side of colliders that retains my character as he's sliding down on the side of it.

i'd like to have no friction/penetration at all on the side of the collider objects or on the collider of my 2d character. As he was sliding on an ice wall :)
« Last Edit: July 24, 2012, 01:18:23 pm by mike2d »

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #3 on: July 24, 2012, 01:48:51 pm »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Colider penetration
« Reply #4 on: July 24, 2012, 01:56:03 pm »
Does this still happen when the animation is disabled on the player? I've got a sneaking suspicion it could be the collider size being modified per frame which could be causing it.

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #5 on: July 24, 2012, 02:20:23 pm »
i've checked collider sizes of every animation frame and its the same for each of them.

with animations deactivated, the problem persists.

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #6 on: July 24, 2012, 02:34:15 pm »
another video to see the penetration of each collider :

http://mamistudio.biz/forums/collision2.m4v

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Colider penetration
« Reply #7 on: July 24, 2012, 02:43:53 pm »
So is this using a character controller or something custom? Sorry, shoulda asked this first
Edit: Also, how are you moving it?

Edit: Can you try replacing it with a standard unity primitive and try it that way? Does it still happen then?
« Last Edit: July 24, 2012, 02:47:37 pm by unikron »

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #8 on: July 24, 2012, 03:18:58 pm »
yes, it's my own controller.

i tried with two primitive cubes + my own controller and its the same problem.

do you think it comes from my controller then ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Colider penetration
« Reply #9 on: July 24, 2012, 03:35:05 pm »
Likely. How are you moving it?

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #10 on: July 24, 2012, 04:03:00 pm »
transform.translate(...)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Colider penetration
« Reply #11 on: July 24, 2012, 11:36:12 pm »
That's a very bad thing to do.

When rigidbodies are on, instead of using transform.translate, in FixedUpdate, use rigidbody.AddForce(worldForces); to move the character. That way you won't be fighting with the Physics engine. This doesn't completely fix the penetration issue, but the boxes do get pushed out a lot quicker. You could probably compensate for it by playing with the scales a bit.

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #12 on: July 25, 2012, 08:34:28 am »
wow,

that piece of answer lead me to an unknown world : CharacterController, Kinematic, static Collider and so on !

I've many things to learn and very basic ones obviously :P

After reading some docs on all that stuff, i'm a bit confused.

If I get it right, I either use an object with rigidbody including its physics OR a character controller with no physics right ?

the advantage of CharacterController is sliding walls, which is a concern in my case but it has a fixed capsule collider (so i lose the benefit of trimmed box in tk2d) and in the other hand, rigidbodies have physics thus gravity ability (which can be simulated with CharacterController if i'm right) but has friction when sliding walls.

so for my 2D game character, WHAT SHOULD I USE ? :D
« Last Edit: July 25, 2012, 08:39:53 am by mike2d »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Colider penetration
« Reply #13 on: July 25, 2012, 06:14:06 pm »
I suggest trying the character controller first. If you can live with the fact that its a cylinder, then that might be good enough for you. This is probably the easiest thing to try and it just works.

You could also try using a box and using AddForce, depending on your needs that might be sufficient. That does work with slopes and stuff.

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Colider penetration
« Reply #14 on: July 25, 2012, 06:26:52 pm »
i've added the CharacterController and after some good changes, everything work like a charm.

thanks for the help, always a pleasure to have your support :)