Gamestudio Physics - Frequently Asked Questions

Q: How can I learn about using physics?

A: Workshop 19 of the tutorial gives an introduction into physics functions. Also, look into the earthball.c sample for simple physics, and into the carlevel project for vehicle physics.

Q: After setting up constraints, my game is running very slowly. What's wrong?

A: The constrained objects penetrate each other at the time of creation, or the constraint parameters are set up incorrectly.

Q: How do I move a physics entity ?

A: Apply a velocity, force or torque to it. If you have set up a constraint on the object, you can also use the phcon_setmotor function to set its movement. Don't attempt to change its position or orientation directly by altering his x,y,z coordinates or angles, or by c_move or c_rotate - this won't work for physics entities.

Q: My object is floating in space, but after applying a force it does not move correctly. It keeps getting faster, vanishes or stops?

A: Long & thin objects, or very small objects can become unstable. Use a bigger and more equally balanced object (sphere). This can be set by calling phent_setmass. Please note that it is possible (and recommended) to use different kinds of geometry for phent_settype and phent_setmass. The phent_settype parameter determines the shape that is used for collision detection, while phent_setmassdetermines mass distribution of an object and affects how the object reacts to forces and torques.

Q: I don't get any gravity even though I set it via ph_setgravity at the beginning of the main function ?

A: Global physics parameters get reset when a new level is loaded. Thus you should first call level_load, wait 1 frame and then call ph_setgravity to set properties of the new level.

Q: My car accelerates, but some of the wheels get bent out of shape ?

A: This problem can occur when constrained objects rotate at high speeds. It is caused by the finite accuracy of the physics equation solver. Some workarounds are: reduce the mass of the constrained objects, reduce gravity, reduce the friction of the wheels, increase the size of the wheels (requires less rotations for same distance).

Q: When I brake and steer sidewards at the same time, the wheels get bent?

A: Braking and steering at the same time applies a sidewards force on the wheels. Either reduce the friction of the wheels, or restrict the steering angle to lower values.

Q: My objects move too fast / too slow...

A: If you've set fps_lock, the game will run with different speed depending on the performance of the PC. Disable fps_lock.

Q: My objects tend to start to vibrate or rotate at rest. When they are 'caught' in a corner they can even spin out of control.

A: Increase the autodisabling speed limits, f.i. with ph_setautodisable(1.0,1.0,10,0.1). But don't make them too high - otherwise, your object might become "sticky". For increasing the physics accuracy, set a higher physics frame rate through ph_fps_max_lock.

Q: I've made a small level with only a few objects, and placed a ball into it. When I kick the ball into the air, it seems to hit an invisible barrier at some position.

A: Check the sky box around your level. The ball possibly collides with a side or the top of the sky box. If there is no sky box around your level at all, the level size is automatically limited to an area that contains all the objects. In this case, create a sky box in WED - a hollow cube with sky texture - and make it large enough for the ball to reach the desired height.

Q: I'm letting a ball roll over a course made of models, but sometimes the ball strangely jumps or stops where the models touch.

A: This is due to small gaps between the models. Let them intersect a little.

Q: How can I restrict movement to two dimensions?

A: Either use two invisible obstacle planes to prevent movement in the third dimension. Or measure an objects position in the third dimension, and apply a small force proportional to the deviation from the desired plane.

Q: How can prevent the collision of a certain physics object with another object?

A: Use phent_setgroup to set both objects to the same group. Objects of the same group don't collide with each other.

See also:

Gamestudio Physics, Physics constants, Physics Constraints ► latest version online