How gravity works

Grab your favourite IDE and tinker with the innards of game engines

How gravity works

Postby Core42 on Wed Aug 28, 2013 2:23 am

How does gravity work in the Source engine? Is it a simple acceleration formula down one axis? How do models know how to orient themselves? Are they simply tied to an axis, which also happens to be the gravity axis, or are they tied to gravity itself?
Core42
Dumpling
Dumpling
 
Joined: Wed Aug 28, 2013 2:15 am

Re: How gravity works

Postby Armageddon on Wed Aug 28, 2013 2:25 am

I think that's hard coded so we have no idea, it's pretty much still Quake 1 player physics though. Why do you need this info?
User avatar
Armageddon
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sun Dec 14, 2008 5:53 am

Re: How gravity works

Postby ErikKiller on Wed Aug 28, 2013 11:16 am

I think they use one of the first iterations of the Havok engine?
I know that in-game gravity in Source has always been tied to a value of '600' or '800', never tried what happens with higher values but the lower you go the floatier things get, that is, the slower they fall.
However objects don't seem to bounce so I assume the gravity is mostly tied to the Z-axis until the value gets so low that objects start to mainly move on the X- and Y-axes, depending on where the applied force is coming from.
I thought about picking up a crate and shooting it away with the gravity gun; so with gravity set to say... '100' it would fly in a direction it is shot and if given enough room would eventually slowly arc towards the floor, I don't think it would bounce anywhere.
Here's another however though. Depending on the force that the object is manipulated with it may bounce off walls and floors, this leads me to believe that the longer the object "flies" the more momentum it loses, thus the less it bounces when finally hitting something.

So to answer your questions:
How does gravity work in the Source engine?
Gravity seems to work pretty on par with the real world gravity, save for the odd sizes in Source and a glitch every now and then.
Is it a simple acceleration formula down one axis?
With prop_physics I'd say no; however there are entities that seem to just fall directly down the Z-axis when rendered in the engine.
How do models know how to orient themselves? Are they simply tied to an axis, which also happens to be the gravity axis, or are they tied to gravity itself?
Well like I said it depends on the value of the in-engine gravity; with higher values the minus Z-axis pull gets stronger, with lower values it gets weaker, kinda like I'd expect the gravity to work in a real world situation
However, you can still manipulate how the object acts on the X- and Y-axes if the gravity or timescale is low enough.
I'd say they're tied to gravity itself?

https://developer.valvesoftware.com/wiki/Gravity
https://developer.valvesoftware.com/wiki/Func_timescale

https://developer.valvesoftware.com/wiki/SDK_Docs
Image
Image
First rodeo? Use the Source SDK Documentation for reference!
User avatar
ErikKiller
May Contain Skills
May Contain Skills
 
Joined: Sun Sep 09, 2007 4:05 pm
Location: Estonia

Re: How gravity works

Postby Core42 on Wed Aug 28, 2013 11:22 am

Curiosity, and I was thinking of trying to mod HL:DM with a gravity hack so that any surface could be a source of gravity, but for it to work properly the player needs to be able to re-orient in relation to the gravity source.

When you say it's hard-coded, do you mean that the SDK is only part of the code we have access to and the rest is simply unavailable?
Core42
Dumpling
Dumpling
 
Joined: Wed Aug 28, 2013 2:15 am

Re: How gravity works

Postby Sandern on Wed Aug 28, 2013 11:39 am

Core42 wrote:Curiosity, and I was thinking of trying to mod HL:DM with a gravity hack so that any surface could be a source of gravity, but for it to work properly the player needs to be able to re-orient in relation to the gravity source.

When you say it's hard-coded, do you mean that the SDK is only part of the code we have access to and the rest is simply unavailable?

Player movement can be completely rewritten to whatever you want. Looked into the gamemovement files yet?

https://github.com/ValveSoftware/source ... .cpp#L1242
Sandern
Regular
Regular
 
Joined: Thu Jun 30, 2005 1:08 pm
Location: Netherlands

Re: How gravity works

Postby Gary on Wed Aug 28, 2013 2:15 pm

It's completely possible to do what ever you want with gravity in Source if you've got a good understanding of the system ...and you're a programming god like Bio here:
Have a question related to modding or something I posted? Something that needs staff attention? I haven't been active lately, but feel free to PM me or message me on Steam(link below)

User avatar
Gary
Interlopers Staff
Interlopers Staff
 
Joined: Wed Dec 16, 2009 12:40 am
Location: USA, FL

Re: How gravity works

Postby Core42 on Thu Aug 29, 2013 1:57 am

Sooo yeah Gary, that's pretty much what I was going for.
And that's why I was asking, to understand so I could manipulate :D
My thoughts on how to make it work were coding a custom entity for Hammer that would re-orient gravity and the player. Either as a point entity or brush entity. Probably make it able to be triggered as well.
EricKiller's link to gravity on the developers wiki shows the VPhysics function being a possible way to manipulate gravity the way I was thinking.
Core42
Dumpling
Dumpling
 
Joined: Wed Aug 28, 2013 2:15 am

Re: How gravity works

Postby ErikKiller on Thu Aug 29, 2013 11:33 am

Core42 wrote:EricKiller

Motherfucker.
Image
Image
First rodeo? Use the Source SDK Documentation for reference!
User avatar
ErikKiller
May Contain Skills
May Contain Skills
 
Joined: Sun Sep 09, 2007 4:05 pm
Location: Estonia

Re: How gravity works

Postby Core42 on Thu Aug 29, 2013 12:10 pm

Damn. Sorry ErikKiller.
Core42
Dumpling
Dumpling
 
Joined: Wed Aug 28, 2013 2:15 am

Re: How gravity works

Postby JiveTofurkey on Fri Sep 27, 2013 4:16 pm

Core42 wrote:Curiosity, and I was thinking of trying to mod HL:DM with a gravity hack so that any surface could be a source of gravity, but for it to work properly the player needs to be able to re-orient in relation to the gravity source.


Also, I find that in HL2DM player movement and orientation is only a part of the larger gravity picture. How about grenades and other thrown physics props? With two parallel planes it seems easy enough to say that once anything passes a midpoint, it falls towards the other side. But real world gravity is spherical, so I don't know how it could be made to work in a cube map. The corners would have three different gravities, could get a bit awkward. Something like dm_escher1 might be a ways off yet, but jumping between floor and ceiling I think could work.
JiveTofurkey
Dumpling
Dumpling
 
Joined: Sat Sep 07, 2013 6:15 pm

Re: How gravity works

Postby Core42 on Fri Sep 27, 2013 4:41 pm

Gravity in game seems to act only as a straight down word force. Applying that straight type of force on say a corner means only the corner would lack gravity. Unless cylindrilical gravity forces are made, to cover right angle corners. As well as spherical of course. They also could be made to be gradient gravity fields, varying a certain amount over distance, so certain fields could fall off in strength, or increase and decrease resulting in a push pull effect.
Core42
Dumpling
Dumpling
 
Joined: Wed Aug 28, 2013 2:15 am

Re: How gravity works

Postby nub on Fri Sep 27, 2013 6:45 pm

Gary wrote:It's completely possible to do what ever you want with gravity in Source if you've got a good understanding of the system ...and you're a programming god like Bio here:


Brb reinstalling Prey.
User avatar
nub
Veteran
Veteran
 
Joined: Tue Nov 15, 2005 1:11 am
Location: Charlotte, NC, US

Return to Programming

Who is online

Users browsing this forum: No registered users