Vehicle Physics

Started by Oz · one year ago · 20 replies · 977 views

Oz
Member
JoinedJul 2022 Posts18 Score100
Forcing myself to do more s&box work, loving the physics engine!
Paddy Pimblett
Member
JoinedMar 2023 Posts2 Score1,630
Damn that's looking sick
garry
Facepunch
JoinedApr 2021 Posts453 Score2,355
Whoa
Jonny
Member
JoinedJul 2022 Posts56 Score5,043
Love this
Oz
Member
JoinedJul 2022 Posts18 Score100
Cheers guys, not sure if the right place to ask, but is there a way to network objects without it auto-replicating the transform?
garry
Facepunch
JoinedApr 2021 Posts453 Score2,355
Why do you want to do that?
Oz
Member
JoinedJul 2022 Posts18 Score100
Atm collisions get cancelled out in multiplayer, i suspect because of the order of things.  Perhaps velocity, position get stomped with old data?
garry
Facepunch
JoinedApr 2021 Posts453 Score2,355
How it's going to work is that if you're the owner of the car you're gonna be in charge of the physics of it. So collisions affecting the car should work fine.

The place it's going to get shitty is when you crash into dynamic physics objects where you're not the owner. In that case on your computer you're controlling the car, and you crash into the box, but the box doesn't move because on the server you're just an object being moved around - rather than a physics object with velocity etc.

I think we can do better here. The car and other physics can be simulated totally serverside, with you just controlling the inputs. I think this is stuff we're going to end up implementing for our Sandbox mode.

You can kind of implement this now, in a roundabout way. Make it so no-one is actually the owner of the car, send inputs from the client somehow (either via an RPC, or another object with syncvars), then use those inputs to control the car.

The obvious downside of this is that you lose any prediction - but this is the same way vehichles work in Rust, which has a similar networking model, and they feel great.
edited one year ago#9
Oz
Member
JoinedJul 2022 Posts18 Score100
I see, i’ll give that suggestion a go today if i find some time, thanks 
edited:
Ok published a version where all vehicles are simulated serverside and im sending inputs only. Collisions etc work just fine, but yeah with ping/packetloss/interpolation it's a noticably delayed feeling, especially for small steering adjustments etc.

Doesn't really show in the video but thought I'd post one anyways

edit: the other feature that'd be really nice is cylinder trace, I saw the request was denied but I still think it would be a useful feature
edited:
Ok below is the result using the 'workaround' for the cylinder trace. It works, but not at all ideal since I have to create a physicsbody that akwardly shows up in the physics debug view, and if I change the radius on the fly that makes things tricky and just generally not fun to code lol.

Braxen 🐟
Member
JoinedJun 2021 Posts204 Score190
@garry
I think we can do better here. The car and other physics can be simulated totally serverside, with you just controlling the inputs. I think this is stuff we're going to end up implementing for our Sandbox mode. 

it makes a huge delay though, like gmod. i tried on my dedicated server and there's like a second of input lag even locally
garry
Facepunch
JoinedApr 2021 Posts453 Score2,355
If there's a second of input lag then you're doing something very wrong
Braxen 🐟
Member
JoinedJun 2021 Posts204 Score190
there's a second of lag between players regardless of vehicles or not, maybe it's specifically a dedicated issue. jumping around, walking, or moving objects is very delayed for things you don't own
garry
Facepunch
JoinedApr 2021 Posts453 Score2,355
If that's the case then I imagine it's a network lerp thing, we'll see what we can do when we start on the sandbox gamemode
Oz
Member
JoinedJul 2022 Posts18 Score100
In my current implementation the input delay is also very noticable, even if it's not a full second. Just 100-200ms kills the handling of the car at high speeds. So I also think there's a case to be made for allowing us to have network objects without explicit transform replication.  Or a way to let us decide what we do with a newly received transform update, where the default behavior would be to just apply it, but games could perhaps check if it's close enough to the localy calculated transform and blend between etc. That's how I do it in my other racing game which features pretty fast driving and A LOT of deliberate collisions and works fine most of the time.

Anyways, here's a cool video to offset my 'rant'


Braxen 🐟
Member
JoinedJun 2021 Posts204 Score190
just having the local visual change before getting the real position would probably help (prediction?), without actually affecting anything in the world
garry
Facepunch
JoinedApr 2021 Posts453 Score2,355
I think our lerping is too delayed when it comes to rigidbodies. We can be a LOT more accurate. You can see this if you turn the physics debug on..
Oz
Member
JoinedJul 2022 Posts18 Score100
Is there a way to tweak the lerping on my end, or is that an engine level thing?

Anyways, I'm having a blast, here's some footage of a truck that I found out a little too late is ripped from GTA5?
Braxen 🐟
Member
JoinedJun 2021 Posts204 Score190
I think our lerping is too delayed when it comes to rigidbodies. We can be a LOT more accurate. You can see this if you turn the physics debug on..

This makes a lot of sense. I've noticed it especially when "grabbing" things via smoothmove. And the player controller collisions in first person but I don't know if those are abstracted

The vehicles look amazing btw
garry
Facepunch
JoinedApr 2021 Posts453 Score2,355
We have been talking about the lerping internally, I think there's a lot we can do
delete
Deleted Post
delete
Deleted Post
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.