Physics Tips

From Physics Simulation Wiki

Jump to: navigation, search

Contents

Learn from the Blender 2.42 Physics Demos

Download Blender 2.42 Physics Demos (3 Mb)

Discuss the issue on the BlenderArtist / Elysiun Game Engine forum

Visit the Elysion Game Engine Forum

See the Bullet Physics Features

Bullet Physics Features in Blender

Avoid Scaling

Don't scale your objects. Apply scale using CTRL-A. If you use Sphere-bounds, make sure the radius fits the sphere:

Image:radiusissue.jpg

Keep masses for dynamic objects similar

If an object of 100 kg rests on an object of 0.1 kg, the simulation will have difficulties. In order to avoid large mass ratios, keep mass of objects similar (in the order of a few kg)

Assign the right bounds type

For a cylinder, choose cylinder, even for non-moving objects. Similar for a box etc. Convex Hull can appoximate meshes for moving objects and static objects.

Image:bounds_choosing.jpg

Don't use too many vertices in Convex Hull meshes

About 4 to 32 vertices should be fine.

Leave the center of the object in the middle of the mesh

See this picture: the center (where the axis are) needs to be inside the mesh, not near to the boundary or outside!.

Image:center_inside_mesh.jpg

Leave the gravity to 10, don't make it too large

The physics simulation works better with smaller gravity, so if possible don't use large gravity.

Avoid very small dynamic objects (< 0.2 units)

Don't make dynamic objects smaller then 0.2 units if possible. For the default gravity, 1 unit equals 1 meter, so any 'side' of the objects should be bigger then that.

No large objects

Don't use large objects, or large triangles.

Don't use degenerate triangles

Triangles that are have extreme long sides as well as extreme short sides can lead to problems.

File:Degenerate shapes.jpg

After a few seconds, the object doesn't move anymore. It doesn't interact with moving platforms etc.

You can manually activate an object, using python command 'object.restoreDynamics'.

Or use the 'no sleeping' button. But don't use the 'no sleeping' button too much, perhaps just for the main character/car etc.

Image:sleeping_deactivation.jpg

How to setup a vehicle

Use the PhysicsConstraints module in Python, and create a special constraint on a rigid body.

  • For collision Bounds it is best to use Convex Hull Polytope. Remember to switch on collision for the chassis polygons!
  • Don't use box, because shifting the center of the box doesn't work.
  • Give the vehicle enough space to move: too narrow roads, too sharp corners and high street curbs and other obstacles that are difficult to avoid are very frequent mistakes which makes driving frustrating, rather then fun.

This constraint allows to add wheels, set tyre friction, suspension, steering and so on.

There is a demo vehicle3_Steering fix.blend in the physics demos.

Image:vehicle_wheelattach.jpg

See the Python Vehicle Script for the code.

  • To improve (vehicle) simulation quality add this line to the python scrips:
PhysicsConstraints.setNumTimeSubSteps(2)
  • don't set friction of track and ground to zero, better lower the friction of car chassis
This way you can add traffic cones and other interesting dynamic objects. Ground friction of 0 means bad physics quality.
  • Try to tweak the form factor (under No sleeping button) a little bit, but keep it close to 0.4. For example 0.45
  • For debugging to see that the raycast for each wheel has correct position and direction use:
#draw the raycast lines
PhysicsConstraints.setDebugMode(1)
  • Make sure you don't use overlays scenes and other camera effects (split screen/viewports) during debugging. The debug lines will not properly show up.

Adding dynamic objects as children doesn't work

Dynamic objects should not have a parent. If you need to add a batch of rigid bodies, check out the addObject2.blend demo, it uses the 'instantAddObject' on the AddObjectActuator.

If you need a complex setup with constaints, like a ragdoll or vehicle, you cannot create that group using an AddObjectActuator. Either use Python for this, to setup the constraints after adding the objects, or wait for future 'constraint userinterface' in Blender.

There is a small gap between the ground and my object

Except for boxes and sphere, there is indeed a tiny gap (0.04 by default) between objects. This gap allows the simulation to run smoother and more stable.

It is not recommended, but you can reduce the gap by using python:

controller = GameLogic.getCurrentController()
owner = controller.getOwner()
owner.setCollisionMargin(0.01)

You can also consider using margin of zero for static/non moving objects, and leave the default margin for dynamics objects.

I want higher quality simulation to create IPO keyframes for animation

If you are just rendering / creating keyframes, and don't worry about realtime you can increate the substeps to improve quality of simulation, using a python script

import PhysicsConstraints
PhysicsConstraints.setNumTimeSubSteps(2)

default is 1. 2 or more make simulation more accurate.

Personal tools