• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
N01

PhysX - Scene scaling, object size, timestep and gravity inconsistency.

30 posts in this topic

OK - well this looks right now.

One quick thing to test is whether your game's accumulation of time is correct. So in your loop you can just print out the total time you've passed to PhysX, and as the game runs, check whether it is counting up in seconds (i.e. compare it with a watch):
 

        ...

If the time printed out is slow, then you need to check the timing code.

 

If the time printed out is fine, then I'm pretty sure PhysX is doing the right thing - just that you have some scaling problems. I'm still not sure from your posts (including #13) how you're determining that the simulation is running slower than expected. If you're looking at the time it takes for a falling object to move the size of a human sized object - you need to be sure that your "human sized object" is really about 2m big. 

 

Since you set gravity to 9.81 m/s that implies your distance unit is metres, and your time unit is seconds. if not - then you need to use a different gravity value.

 

Feel free to upload a pvd capture and I'll take a look...

 

 

i tried outputting elapsed time through printf and it does output realtime seconds quite perfectly. so i guess, timestepping is fine.

i just determine it visually, objects fall and interact to slowly.  i guess, problem is scaling. because in my scene, 1 unit is like 5-6cm and objects have corresponding weight. if i increase gravity, it doesn't go well. objects start shaking on the ground. and if i re-scale my scene by a factor of 0.05f(1/20), speed gets normal. although it seems like precision for smaller objects is lost. if i shoot a dense sphere with high velocity at a small object, it most likely will just pass through, it just feels a bit off.

 

it says "Error You aren't permitted to upload this kind of file", so i uploaded PVD clip here:

http://rghost.net/private/48672806/63f9e682ffa0f7a14746166f83a12cd0

it demonstrates test scene without any re-scaling, so it's slow-mo, and i just fly around for a bit, shooting spheres.

Edited by N01
0

Share this post


Link to post
Share on other sites

 

Wait, is that actually representative of your actual code? Those calls to sleep (especially in the physics thread) will not be doing you any good.

The accumulation loop you posted is design to run as quickly as possible (i.e. in a while(true) style loop) and fire the Physics events at the correct time. With the setup you have now the simulation will not be being called at the correct frequency due to differences in sleep time and the fact that your time deltas are going to be huge.

 

this is simplified code. but yes, my threads do sleep, but they also do take in account time they were busy with processing, so they don't sleep more than it's required. and my deltaTime is not really huge, it's always around 0.033sec with rare deviations of 0.001sec. this loop is not designed to run continuously, it's designed to compensate for elapsed time. the only case, then such organisation may cause trouble, is if processingThread cannot finish in given time of 30ms, but that is undesirable for application in general, so i shouldn't allow it to happen. and you generally don't want any continuous  thread to run without any sleeping, it is similarly irresponsible and dumb as using vsync to limit your framerate.

Edited by N01
0

Share this post


Link to post
Share on other sites


i just determine it visually, objects fall and interact to slowly.  i guess, problem is scaling. because in my scene, 1 unit is like 5-6cm and objects have corresponding weight. if i increase gravity, it doesn't go well. objects start shaking on the ground. and if i re-scale my scene by a factor of 0.05f(1/20), speed gets normal. although it seems like precision for smaller objects is lost. if i shoot a dense sphere with high velocity at a small object, it most likely will just pass through, it just feels a bit off.

 

OK - well if 1 unit is, say 0.05m, then you need to set gravity to 9.81 / 0.05, and get rid of your time scaling.

 

That's not all though - you need to:

 

1. Pass in an appropriate set of scales when you create the physics SDK, since the defaults will be inappropriate. Look up physx::PxTolerancesScale

 

2. Increase the contact offset on the shapes you create - by a factor of 1/0.05. 

 

The second thing should get rid of the jittering. 

 

You also need to consider what density you want, and what your mass units are. If you want mass in kg, then you will have pretty weird densities, because you'll have a factor of 20^3.

 

A better option is to work in metres, kg and seconds - either by converting your source/game assets, or by scaling whenever you pass things across the PhysX API.

 

One general thing though - it really is (in my experience) worth trying to be quite precise when dealing with physics simulation. Even just to use a physics SDK you need to have a reasonable understanding of physics (what's the difference between force and impulse etc), and be quite careful - otherwise you may hack things into working, but in the future (e.g. if you change the timestep) it can all come back to haunt you! 

 

I'll try to have a look at the PVD later...

0

Share this post


Link to post
Share on other sites
OK - well if 1 unit is, say 0.05m, then you need to set gravity to 9.81 / 0.05, and get rid of your time scaling.

 

That's not all though - you need to:

 

1. Pass in an appropriate set of scales when you create the physics SDK, since the defaults will be inappropriate. Look up physx::PxTolerancesScale

 

2. Increase the contact offset on the shapes you create - by a factor of 1/0.05. 

 

The second thing should get rid of the jittering. 

 

You also need to consider what density you want, and what your mass units are. If you want mass in kg, then you will have pretty weird densities, because you'll have a factor of 20^3.

 

A better option is to work in metres, kg and seconds - either by converting your source/game assets, or by scaling whenever you pass things across the PhysX API.

 

One general thing though - it really is (in my experience) worth trying to be quite precise when dealing with physics simulation. Even just to use a physics SDK you need to have a reasonable understanding of physics (what's the difference between force and impulse etc), and be quite careful - otherwise you may hack things into working, but in the future (e.g. if you change the timestep) it can all come back to haunt you! 

 

I'll try to have a look at the PVD later...

 

 

i did the latter, found precise scaling factor for the scene and rescaled while passing to PhysX. it shouldn't couse trouble in future(unlike other option), less fiddly and i already had this option programmed into my engine.

0

Share this post


Link to post
Share on other sites


i did the latter, found precise scaling factor for the scene and rescaled while passing to PhysX. it shouldn't couse trouble in future(unlike other option), less fiddly and i already had this option programmed into my engine.

 

The objects in the PVD doesn't look like they've had this scaling. Gravity in the scene is 9.81 - which means you're using metres as your distance unit. Yet the box in the scene is 24m long - and similarly the capsules - if this is supposed to be a road with debris(?) it's absolutely huge, and no wonder everything moves in a way that looks like it's in slow motion.

0

Share this post


Link to post
Share on other sites
The objects in the PVD doesn't look like they've had this scaling. Gravity in the scene is 9.81 - which means you're using metres as your distance unit. Yet the box in the scene is 24m long - and similarly the capsules - if this is supposed to be a road with debris(?) it's absolutely huge, and no wonder everything moves in a way that looks like it's in slow motion.

 

yes, i've stated in that post(where i posted a clip from PVD), that PVD clip is before re-scaling scene to 1u=1m scale.

here's PVD clip with scene rescaled:

rghost.net/private/48675822/15cb958a221323afef1c3231e4bd4451

Edited by N01
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0