2
\$\begingroup\$

So, my problem is that my play when he walks over to another sprite he will stop.

I fixed that by adding a physics material with 0 density and 0 friction to the player

and adding a circle collider instead of a box collider to the player.


However now I have another problem where my character keeps bumping when it enters another sprite.

The sprites are at the exact same height, the objects are just as big and the colliders have the exact size.

I would like to get a fix for this problem, which still allows me to use Rigidbody2D.AddForce for movement.


Video of my problem :

Video :>


How to recreate the problem :

Make a sprite, add a Circle Collider 2D to it and a Rigidbody2D.

That will be the player.

Next, make some platforms and add a Box Collider 2D

Now, if you let your player walk over the platforms it will (or should..) start bumping.

\$\endgroup\$
  • \$\begingroup\$ I saw your video, but can't replicate the problem. If you have an online repo of your project, I could download it and start it up in Unity. \$\endgroup\$ – user79422 Feb 20 '16 at 20:41
  • \$\begingroup\$ @codeepic This happens all the time to me, here's what I do to create my problem : Create a 2D circle collider and attach it to a sprite GameObject with a rigidbody2D, add 3 sprites to your scene, all 3 should have 2D box colliders, make the player walk over them using AddForce, and it should start bumping when the player "crosses" a sprite. Hopefully this made sense. \$\endgroup\$ – BiiX Feb 21 '16 at 1:17
  • 1
    \$\begingroup\$ I'm having the same issue. Plus my design requires some of the object to have box colliders. I am very interested if someone found a real solution that still uses Unity's rigidbodies \$\endgroup\$ – tyjkenn Feb 21 '16 at 23:43
  • \$\begingroup\$ I can see a box collider too on player, larger in height, is it so or I am just confused? \$\endgroup\$ – Hamza Hasan Feb 23 '16 at 5:40
  • \$\begingroup\$ If it is so, then that is the only problem \$\endgroup\$ – Hamza Hasan Feb 23 '16 at 5:50
2
+50
\$\begingroup\$

Short answer: Don't build a 2D jump and run using a physics engine. I worked on such a project and we were mostly fighting the physics engine.

Long answer: Have less, bigger colliders. We built our levels using tiled. We placed sprites and colliders seperately so one block of floor got only one, big collider. It still has issues at ramps, when falling on the edge of a platform, and so on. There were lots of raycasts and custom forces involved and it was not pretty.

You could also try and merge the colliders / create them on the fly from the sprites, though this is probably more complex.

\$\endgroup\$
  • \$\begingroup\$ Tiled fixed all of the problems! :) \$\endgroup\$ – BiiX Feb 23 '16 at 11:32
  • 1
    \$\begingroup\$ It doesn't seem like Tiled would work for my purposes considering I am using an in-game level editor. I already tried making my own physics system, but it proved to have more glitches than Unity's, especially with all the force interactions my game requires: push blocks, high-power fans, trampolines, etc. I got it working with Unity's rigidbody physics perfectly except for the occasional catching on corners between blocks. Unless there is a fix, merging colliders may be the only option. \$\endgroup\$ – tyjkenn Feb 23 '16 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.