Hello Guest

Author Topic: Something about physics...  (Read 11029 times)

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Something about physics...
« on: May 29, 2013, 04:43:19 pm »
So I started to play around with physics and I noticed a problem: everything is so floaty. I know I could adjust the physics setting but I also ran into some weird physics simulation. Then I read about the unity rigidbody page (http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html), it says using the right size for object or the simulation may become inaccurate.

quoted from the page:

Use the right size
The size of the your GameObject's mesh is much more important than the mass of the Rigidbody. If you find that your Rigidbody is not behaving exactly how you expect - it moves slowly, floats, or doesn't collide correctly - consider adjusting the scale of your mesh asset. Unity's default unit scale is 1 unit = 1 meter, so the scale of your imported mesh is maintained, and applied to physics calculations. For example, a crumbling skyscraper is going to fall apart very differently than a tower made of toy blocks, so objects of different sizes should be modeled to accurate scale.

If you are modeling a human make sure he is around 2 meters tall in Unity. To check if your object has the right size compare it to the default cube. You can create a cube using GameObject->Create Other->Cube. The cube's height will be exactly 1 meter, so your human should be twice as tall.


So then I looked at my collider for player and it's 250x400, which means it's 250 meters x 400 meters! That's huge for a player. So I wanted to adjust to something like 1x2 which is 1 meter x 2 meters, but I also wanted to keep the transform scale to 1 so the only thing I can adjust is ortho camera size.

Here the problem comes, I'm using a normal camera of ortho size of 100, if I adjust it to says 10, everything become very small and then I had to adjust the target ortho size in sprite collection so they became the right size, but the whole scene would be messed up -- there are huge gap apart from everything due to the scaling, and it's unpractical for me to rebuild all the scene. Also I was thinking if using 2dtk camera, in which you can't adjust the ortho size at all, what should you do about the size in regards of physics simulation?

Just want to know you guys' solution since everyone here are making 2D games. Does the size matters for 2D game? It surely matters for 3D but what about our situation? I do need to use some intense physics for possible ragdoll but nothing compares to realistic 3D physics. And to adjust all my objects for a hundred-time's-scale to fit the right size doesn't sound practical, especially if using a 2DTK camera such adjust became impossible if you want to keep the transform scale at 1. How you guys think?

Thanks
« Last Edit: May 29, 2013, 04:46:51 pm by ryf9059 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Something about physics...
« Reply #1 on: May 29, 2013, 04:53:15 pm »
You have 2 options.

1. Don't use tk2dCamera, set up your camera settings so the physics objects are "the right size". You can work out an ideal ortho size - this article goes into a bit of detail: http://unikronsoftware.com/2dtoolkit/doc/2.00/tutorial/choosing_camera.html

2. Set up gravity, etc. to work better at whatever unit you're dealing with. Details here: http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1746.0.html

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Something about physics...
« Reply #2 on: May 29, 2013, 05:01:14 pm »
What I do now is setting my gravity to -100, but I ran into weird simulations like falling through ground, being bounced back to 1000 kilo's high out of nowhere when landing on ground, being pushed around out of no where when landing on ground, etc, etc.

Have you ever encountered werid thing like this if using a normal camera with custom gravity? What should I do to solve this?


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Something about physics...
« Reply #3 on: May 29, 2013, 05:54:16 pm »
Did you increase physics depth as described in the 2nd faq post?

Unity doesn't seem to have issues with large scales from my tests, but does if the object is really really large, but super thin in one axis. In that case, floating point precision will cause issues. So when you look at your physics scene from the side, you should see a reasonable amount of thickness to it.

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Something about physics...
« Reply #4 on: May 29, 2013, 06:21:14 pm »
Yes I have my collider depth setup as 50, but weridness still happens

My ortho size is 100 so everything is large, like you can see 250x400 for a player if in meters (I don't know if that's considered really large, but definately large), but in my actual game the window height is about 5 meters if using standard default unit (3 players stack on top of one another will exceeds the window height), so according to your first faq post my ortho size should be 2.5 if using default unity settings, which is far from being 100 as the current situation (currently with my 100 ortho size the world is around 500 meters tall). But the window size varies depending on different levels (in which they might not be pixel-perfect but rather a slightly scaled down version to contain more things), that's another reason I didn't use 2dtk camera.

And as a 2D side scrolling game my world is going to be long, probably 1 kilo or more to scroll, and with height of 10-15 meters (window size as 5 meters so player can explore some vertical space), so my world is estimated as 10x1000 per se, not sure if this world is considered really big (I might split the world into sub scenes so to decrease the distance needs to run per scene).


For physics weirdness I've made post in unity, just to get an idea
http://answers.unity3d.com/questions/465215/object-jump-different-distance-while-using-the-sam.html

Do you have any suggestions?

Also, although I build my scene already but it's only 1/5 level or less so it's not too horrible to rebuild it using standard 2.5 ortho size. Based on my game size and all the situation mentioned, what do you think is the best for me to do?
« Last Edit: May 29, 2013, 07:48:55 pm by ryf9059 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Something about physics...
« Reply #5 on: May 29, 2013, 09:00:37 pm »
Can you create a repro case demonstrating the issue? If so email to support at unikronsoftware dot com.
I still think it might be possible to make this work. Pretty sure we're just missing a setting somewhere.

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Something about physics...
« Reply #6 on: May 30, 2013, 11:22:05 am »
Can you create a repro case demonstrating the issue? If so email to support at unikronsoftware dot com.
I still think it might be possible to make this work. Pretty sure we're just missing a setting somewhere.


I found that there was another problem with thinkscroller, so I fixed that, most of the physics weridness is gone  :)

The only problem that's surely to do with the physics itself (as I can tell) is the jumping problem: if the player jumps on the surface of a whole collider, it jumps normally, but if it jumps on the surface of two colliders, it jumps much lower, as I mentioned in the unity post.

I have recorded a video showing the problem. If you still think it's necesary to see the project itself, I till try to make a minimum example.

http://screencast.com/t/tqmsLmdH0qC

The physics setting for this scene is -200 btw

Now my inclination is to rebuild the scene with default setting, since not only physics needs to be utilized, I also want to use doppler effect for sound source etc, if using the current scene I might end up twinking a lot of values. But anyways, I still want to know what caused the weird jumping problem.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Something about physics...
« Reply #7 on: May 30, 2013, 11:57:07 am »
The "jump" issue straddling collider boundaries is a known Unity issue. You can reproduce it with 2 Unity boxes at default scales side by side, and a box jumping on it. I don't know of any workaround to this except just mitigating it somehow, or using your own raycast physics.

I have a feeling the thinkscroller plugin is moving objects to achieve parallax - that might not be the best way to do it when you have physics objects in there, it could cause serious issues, as you've probably already found.

You can rebuild it with more native resolution settings. It might be better if you're using doppler ,etc.

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Something about physics...
« Reply #8 on: May 30, 2013, 03:02:49 pm »
Thanks for all the answers! You are awesome!

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Something about physics...
« Reply #9 on: June 01, 2013, 06:04:47 pm »
The "jump" issue straddling collider boundaries is a known Unity issue. You can reproduce it with 2 Unity boxes at default scales side by side, and a box jumping on it. I don't know of any workaround to this except just mitigating it somehow, or using your own raycast physics.

I have a feeling the thinkscroller plugin is moving objects to achieve parallax - that might not be the best way to do it when you have physics objects in there, it could cause serious issues, as you've probably already found.

You can rebuild it with more native resolution settings. It might be better if you're using doppler ,etc.

Btw, I have another question, for the physics issue in unity, can I use the static sprite batcher to merge all the colliders into a single one? Is there such a feature?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Something about physics...
« Reply #10 on: June 01, 2013, 07:21:46 pm »
You could use the static sprite batcher, but you couldn't possibly merge EVERYTHING in your level could you?

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Something about physics...
« Reply #11 on: June 02, 2013, 04:47:10 am »
You could use the static sprite batcher, but you couldn't possibly merge EVERYTHING in your level could you?

No, since my level is huge and I have slipt the batcher in to subsections to avoid unnecessary rendering. But it should at least avoid the problem for the most part.

Just wondering, if there is no current work around for this unity issue, how do 2D games solve it in general if there is a lot flat ground like in mine? Did unity say anything about it?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Something about physics...
« Reply #12 on: June 02, 2013, 11:56:24 am »
I think one (possibly the most logical) way to completely avoid it is to use your own custom character controller. Checking my bug logs, I don't think I ever submitted a bug report to Unity - I know I built a test case, but I can't for the life of me remember what I did with it.

ryf9059

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Something about physics...
« Reply #13 on: June 02, 2013, 03:16:22 pm »
I think one (possibly the most logical) way to completely avoid it is to use your own custom character controller. Checking my bug logs, I don't think I ever submitted a bug report to Unity - I know I built a test case, but I can't for the life of me remember what I did with it.

I just read something about the character controller. So for my 2D game, do I need a rigidbody at all if I use character controller? Also the character controll that goes with unity is in javascript, I do know javascript but I feel unconfortable having javascript code in my C# code. Can I even mix using these two? Or do I really need to write my own character controller for better sake?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Something about physics...
« Reply #14 on: June 02, 2013, 03:19:10 pm »
The sample in Unity is in JS. The character controller itself is a core component in Unity. I suggest porting it to c# if the rest of your project is in c#...

Or look at JNAMobiles 2d platform controller - I can't offer any guarantees with that, but the videos look very promising.