Hello Guest

Author Topic: Collider  (Read 9510 times)

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Collider
« on: June 25, 2012, 03:09:59 pm »
hi,

i've put a cube in my scene with collider and rigidbody and i added an animated sprite onto it with its collider and rigidbody too.

when i hit play, the sprite goes through the cube a couple of pixels instead of sitting on top of it.

how can i fix that ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collider
« Reply #1 on: June 25, 2012, 03:21:11 pm »
If your ortho size is small (around 1), Unity's collision system with the default parameters will penetrate slightly. If you want to avoid this, you'll have to either change physics settings in Edit > Project Settings > Physics, or change the ortho size of the scene (and the ortho size in the sprite collection to compensate for this too).

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Collider
« Reply #2 on: June 26, 2012, 08:36:16 am »
my camera ortho was set to 1.8 indeed, but now it is at 5 and still the same problem...

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Collider
« Reply #3 on: June 26, 2012, 08:40:42 am »
ho wait, there's a tk2d camera round here  ::)

but now my game panel doesn't show anything with this camera :(

i can see my scene in the camera preview (when the tk2d camera is selected) but nothing appears in the game panel...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collider
« Reply #4 on: June 26, 2012, 08:41:01 am »
Verify that this is indeed the problem first...
Edit > Project Settings > Physics

Set "Min penetration" to something a lot smaller, like 100x smaller  - 0.0001 and see if it makes things better.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collider
« Reply #5 on: June 26, 2012, 08:41:35 am »
ho wait, there's a tk2d camera round here  ::)

but now my game panel doesn't show anything with this camera :(

i can see my scene in the camera preview (when the tk2d camera is selected) but nothing appears in the game panel...

Don't bother with the tk2dCamera in this particular case, that will skew the physics the other way.

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Collider
« Reply #6 on: June 26, 2012, 08:46:34 am »
nice, the min pen. did the trick, thanks :)

so what's the purpose of the tk2d camera then ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collider
« Reply #7 on: June 26, 2012, 09:02:46 am »
The tk2dCamera has 1 world unit = 1 pixel. Its useful for arranging UI elements or in any other case where this is useful. When physics is enabled though, the number of units vertically changes depending on resolution, and as such won't be as useful on a physics based scene. It may be exactly what you want though, depending on what you're after.

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: Collider
« Reply #8 on: June 26, 2012, 09:22:12 am »
ok thank you !

daklab

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Daklab - Experiments, Projects, Designs, Tips, and Tutorials Related to Creative Coding
Re: Collider
« Reply #9 on: June 27, 2012, 06:06:46 am »
So what is the best practice for 2D physics mobile games when using tk2d? Is it to use two cameras in the scene: 1 tk2d camera for rendering UI and then 1 ortho camera set similarly to the tk2d_demo - Polygon Colliders demo - to render a physics scene?

Are there any "penalties" or performance issues I should be aware of if I simply want to use the tk2d camera for both my UI and for rendering my physics scenes?

If done this way what is the preferred setting for Edit > Project Settings > Physics > Gravity (say for a 800x480 target resolution)?

Thanks to anyone who can drop some tk2D knowledge, I just purchased it last night :)
Braindrop Labs - Games. Apps. Coded Art. www.braindroplabs.com

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Collider
« Reply #10 on: June 27, 2012, 01:30:00 pm »
That could work well. There won't be any significant performance loss if you use 2 cameras or 1.
If you want to use the tk2dCamera for both UI & rendering, you can work out the gravity, etc. by how many pixels you want to represent 1 meter. The default gravity will treat 1 pixel as 1 meter.