2D Toolkit Forum
2D Toolkit => Support => Topic started by: mike2d 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,
-
The penetration threshold is in
Edit > Project Settings > Physics
-
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 :)
-
here's what i'm talking about :
http://mamistudio.biz/forums/ColliderProblem.flv (http://mamistudio.biz/forums/ColliderProblem.flv)
-
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.
-
i've checked collider sizes of every animation frame and its the same for each of them.
with animations deactivated, the problem persists.
-
another video to see the penetration of each collider :
http://mamistudio.biz/forums/collision2.m4v (http://mamistudio.biz/forums/collision2.m4v)
-
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?
-
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 ?
-
Likely. How are you moving it?
-
transform.translate(...)
-
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.
-
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
-
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.
-
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 :)