Comprehensive Gmod physics guide (your help needed)

Go to http://www.wiremod.com/forum/wiremod-general-chat/17874-comprehensive-gmod-physics-guide.html

Or

http://wiki.garrysmod.com/?title=Physics

The old copy posted here was badly formatted and out of date.

I totally understand.

I agree
Long thread. Yet so… useful! Im gonna read this when I get my degree.

[editline]06:14PM[/editline]

So. It was… copied and pasted.:Dawkins102::google:

It’s the same person.
http://www.wiremod.com/forum/wiremod-general-chat/17874-comprehensive-gmod-physics-guide.html

There is no “GMod Physics Engine”.

GMod is part of the Source Engine, and Source uses a modified version of the Havok Physics Engine. Go learn about that, instead of talking about “Gmod Length Units” as they don’t exist.

Gmod Physics Engine = the physics engine that gmod uses.

I don’t have any way to test the other forms of the Havok engine really, so i can only talk about gmod physics. I’d generalise it to “Havok” if I knew for a fact that all the constants and equations were the same (which they blatantly aren’t)

Oh, and Gmod Length Units = the length units gmod uses…

All the constraint types in Source are documented here:

There is a free download here:
http://www.havok.com/index.php?page=general-information
that contains in-depth documentation of the Havok engine in its entirety.

Also, Havok measures things using Imperial - think inches and feet.

Edit:
Not to mention, most of your equations are just re-representations of known physics formulae anyway.

Thanks for the links, they look useful, however don’t go into quite the depth I’m aiming for - I literally want equations to define the behaviour.

Check the wiremod thread lol, the units stuff has been done to death.

in gmod; mass is Kg, length units are 0.75 of an inch

And yeah, most of the equations are straight from real life, because that is where the havok coders obviously got them as well. I include them because i’ve tested to make sure they work in gmod like they do in real life (some don’t) and also to tell people who wouldn’t know them otherwise.

The equations you want are included in the Havok SDK - burrowing through that will make you very happy, I’m sure. :smiley:

In case you didn’t know, Force is measured in Imperial Pounds (lbs) in Source games.

Sweet, I obviously did try googling for documentation before I went and tested all this in game, but nothing came up :frowning:

Edit: yeah like I thought, the havok documentation is very general, it doesn’t include any equations or constants. Still, it gives some insight into how the engine actually works at a deeper level (i.e how the numerical integration works)

Havok is a platform in which the game creator ie source or garry, can input all the physics equations they want, and end up with a working physics engine. The thing is it’s those equations that I want.

This is the actual physics engine http://developer.valvesoftware.com/wiki/VPhysics

Maps, architecture and prop models use a scale of 1 foot = 16 units.
Skyboxes (which are 1/16th scale of ordinary maps) use 1 foot = 1 unit.
Human Character models for Source Engine currently use 1 foot = 12 units.

I believe that’s the discrepancy you’re noting there.

Yeah it is. 1 foot = 12 inches = 16 length units. 12 / 16 = 0.75 length units per inch.

Ohmygod

Mmmonster bump. I’ve made a wiki page for this.

Very nice, this info could be useful to make your own simple physics engine.

Heh, well here’s a simple e2 holoball that uses a few of the equations if you are interested :wink:. It’s pretty fun to change the constants to see how it will react. It bounces, falls due to gravity, has air & water drag, floats, and conforms to the gmod speed limit. (It’s not a perfect physics sim though, don’t expect too much from it).



@name Ball
@inputs 
@outputs [Gravity Colour Position Velocity Acceleration Force Drag Waterdrag Bounceforce Hitpos Surfacenorm Bouyancy]:vector Coltimer Underwater Waterd
@persist Mass Radius Airdensity Cofr Timestep Waterdensity Collide Bounce Theta Waterlevel Waterd Bouyancycoef Ranger:ranger 
@persist 
@trigger 
runOnTick(1)
Mass = 100
Radius = 20
Airdensity = 0
Waterdensity = 100
Cofr = 1
Gravity = vec(0, 0, -600) * Mass
Bouyancycoef = 800
Colour = vec(255, 100, 0)
Speedlimit = 4000
Waterlevel = -30.5
Timestep = 1/67
if (first()) {
    Velocity = vec(100, -100, 0)
    Position = entity():pos() + vec(0, 0, 1000)
    holoCreate(1, Position, vec(1, 1, 1) * Radius / 5.876)
    holoModel(1, "hqsphere")
    holoColor(1, Colour)
}
####collision detection####
Ranger = rangerOffset(220, Position, Velocity:normalized())
Hitpos = Ranger:position()
Surfacenorm = Ranger:hitNormal()
Bounce = 0
if (Ranger:distance() < Radius & !Collide) {
    Collide = 1
    Bounce = 1
    Position = Hitpos - Velocity:normalized() * Radius
    } 
if (Collide) {
    Coltimer++
    #holoColor(1, vec(0, 255, 0))
    if (Coltimer > 10) {Collide = 0, Coltimer = 0, holoColor(1, Colour)}
}
####Water detection####
#if (holoEntity(1):isUnderWater()) {Underwater = 1} else {Underwater = 0}
Waterd = Position:z() - Waterlevel
if (abs(Waterd) < Radius) {
    Theta = 2 * acosr(abs(Waterd) / Radius)
    if (Waterd > 0) {
    Underwater = ((Theta - sinr(Theta)) / (2 * pi()))^2
    } else {
    Underwater = 1 - ((Theta - sinr(Theta)) / (2 * pi()))^2
    }
} elseif (Waterd < -Radius) {Underwater = 1} else {Underwater = 0}
####physics engine######
Bounceforce = Bounce * ((Surfacenorm:dot(Velocity) * Mass) / Timestep) * -Surfacenorm * 2 * Cofr
Drag = 8.18e-6 * Airdensity * pi() * Radius^2 * Velocity:length()^2 * -Velocity:normalized()
Waterdrag = Underwater * 8.18e-6 * Waterdensity * pi() * Radius^2 * Velocity:length()^2 * -Velocity:normalized()
Bouyancy = vec(0, 0, Underwater * Mass * Bouyancycoef)
Force = Gravity + Drag + Waterdrag + Bounceforce + Bouyancy
Acceleration = Force / Mass
Position = Position + Velocity * Timestep + 0.5 * Acceleration * Timestep^2
Velocity = Velocity + Acceleration * Timestep
if (Velocity:length() > Speedlimit) {Velocity = Speedlimit * Velocity:normalized()}
holoPos(1, Position)
# made by tolyzor


Me and Wenli had a stab at getting the explosive damage formula yesterday. Although we couldn’t get it exact (its currently ~2% wrong for various reasons), we learnt a lot you probably didn’t know;

* Props and players can be shielded from explosive blast by other props. A prop will shield about 80 damage, plus an increasing amount as the shield's mass increases. Once the shield is more than 350kg, no damage will be done.

* Prop shields can be defeated; surround your explosive in a very low mass prop, and the blast damage will drop by 80, but then no other props can shield it whatever their mass.

* Damage scales linearly with distance, but the distance depends on the collision mesh of the prop being damaged and its orientation. If a slender prop is pointing at an explosion, it will be heavily damaged, if it's pointing at an angle, it will not.

These factors and more are descried by the equations, but I just thought I’d say them in plain English for once as an example of what all the equations can say if you read into them.