Bullet physics in mta

Recommended Posts

For long time i considered to do something with physics in mta. For now doing even simplest things such falling box, tree on flat area looks cartoonish. In my history of i saw few attempts of doing simple physics, mostly it was in closed area without bigger interactions with poor performance due you just can't calculate collision in other way than processLineOfSight, isLineOfSightClear or read directly .col file as Tederis did.

I started with something to render things, thats how FBX to bypass default rendering to handle future i'll introduce in future.

That's how bullet physics project born, first idea how to use react physics, works simillar but is lighter and general smaller project but 0x416c69 suggested to use bullet. I'll use this topic also to prepare long list of features it contains for future copy paste to PR and wiki page


The main assumption is to allow for create multiple world with completly independed simulations, get and set detailed information about current step of simulation, fully control how everything is simulated, quality of collision tests, speed and a lot more.

i'm trying keep amount of functions low, because if that most stuff is packed into one function.
Syntax and name of some function might change in future or along suggestions.
Not all properties supports every physics element, some are only get, other set only, however most of them are set/get

Current stage:

I already implemented function such a:

  1. physics physicsCreateWorld() - responsible for creating new world for simulations, return element which will use later.
  2. physics-rigidbody physicsCreateRigidBody( shape-type, mixed arguments ) - creates rigid body which is use to simulation bahaviour of non-static shapes, collisions ( currently only few models in mta can do this in simple way ).
  3. physics-rigidbody physicsCreateRigidBodyFromModel( model ) - used to create rigid body directly from collision data taken from gta model.
  4. physics-static-collision physicsCreateStaticCollision( shape-type, mixed arguments ) - creates static collision which will not move at all ( it is still possible to move it by Lua script )
  5. physics-shape physicsAddShape( shape-type, mixed arguments ) - if you create compound shape, this function let you add more shapes into static collision or rigid body
  6. bool physicsSetProperties( any physics element, physics-property, mixed arguments ) - main function to control physics, rigid bodies, static collisions, shapes. Works in simillar way as handling functions.
  7. mixed physicsGetProperties( any physics element,  physics-property ) - same as above, but getting properties
  8. bool physicsDrawDebug( physics ) - use to visualization of world, must be used in render function
  9. bool physicsSetDebugMode( physics-debug-mode, enabled ) - use to turn off/on debugging features
  10. bool physicsBuildCollisionFromGTA( physics ) - used to create static collisions in specified world from original collisions, doesn't create whole world instantly, require to move player around world to load collision data.
  11. physics-constraint physicsCreateConstraint( physics, physics-rigid-body, physics-rigid-body, constraint-type, mixed arguments ) - use to connecting two or more rigid bodies into one entity
  12. bool physicsApplyForce( physics-rigid-body, vector from, vector to ) - pushing rigid body in particular point you choosed.
  13. bool physicsApplyCentralForce( physics-rigid-body, vector direction ) - apply force from central position of rigid, it's more like "accelereate", should be used more than once at the some period of time
  14. bool physicsApplyCentralImpulse( physics-rigid-body, vector direction ) - setting position from center of rigid
  15. bool physicsApplyDamping( physics-rigid-body, float force ) - i'm not sure, but it should slow down velocity and rotation of model by specified amount of units
  16. physicsApplyImpulse( physics-rigid-body, vector direction ) - i'm not sure how it works 
  17. physicsApplyTorque( physics-rigid-body, vector rotation ) - same as physicsApplyCentralForce but for rotation
  18. physicsApplyTorqueImpulse( physics-rigid-body, vector rotation ) - setting rotation speed

physics-properties: "mass", "position" ,"rotation", "sleepingthresholds", "restitution", "scale" "debugcolor", "filtermask", "filtergroup", "stiffness"

`sleepingthresholds` means how slow rigid must move/rotate to sleep, it makes stops moving at all but still can be pushed by other rigids
`restitution` bounciness, between 0-1 but accept any value above

`stiffness` - for fixed constraint

`filtermask` i still figuring out how it work, but should let you use 32 bit mask to set which rigid with which should collide

Bullet documentation:
page 13 contains useful information when which shape should be used

physics-constraints: "pointtopoint", "hidge", "fixed", "slider"

Physics-shapes: "box", "sphere", "capsule", "cone", "cylinder",  "heightfieldterrain", "compound", "trianglemesh", "convexhull"

`compound` is used for constructing rigid made of various shapes

Plans for future:

  1. "heightfieldterrain" shape type accept black-white texture for faster creation
  2. Support for cloths, soft bodies

Videos are availiable at my youtube channel
screenshots and gifs of current progress:


unknown.png Ray casting

wonsz.giffixed constaraint

snake.giffixed constraint

unknown.pngscaled heightmap

unknown.pngcapsule shape

unknown.pngcone shape

unknown.pngcylinder shape

unknown.pngheightfield terrain filled with spheres

unknown.pngsingle sphere in heightfield terrain

unknown.pngheightfield terrain scale and filled with spheres

unknown.pngexample usage of physicsCreateRigidBodyFromModel

unknown.pngexample usage of physicsCreateRigidBodyFromModel

unknown.pngrandom spheres and boxes spreaded around world, green are sleeping one



Documentation i use:

I'm waiting for your suggestions

Topic not finished

Edited by CrosRoad95
Raycast example
  • Like 12
  • Thanks 3

Share this post

Link to post

Is there really need physics for bullets? Render distance in MTA on its own is really terrible, as such having bullets that fall slowly wouldn't make much of sense as bullet wouldn't start falling before it would reach render distance. None the less, this looks really fun to play around with and make some cool stuff with so i could see some other use with this.

Share this post

Link to post

Awesome idea, however it sounds impossible for a single person. Since collisions are client-side, bullets, object and ped ragdolls will be asynced. It may cause additional problems in future so you have to deal with server as well.

Anyway i guess it's time to go onto the next level for good old SA so good luck 💪

Share this post

Link to post

Will your bullet physics increase the default GTA collision range of 300 meters? Its pretty annoying to have stuff falling through the ground when reaching the 300m distance mark. And it should be no problem for a powerful PC.

Share this post

Link to post

  • Recently Browsing   0 members

    No registered users viewing this page.