Physics & Networking?

Cyranh

Member
Hey there,

I just made a server and client system, which works perfectly fine, but when I enable the physics world, my character gets stuck in the 0, 0 corner. If you download the LAN_Platformer demo from GameMaker: Studio, and you enable the physics world, every object with physics enabled gets stuck in the corner. Can anyone explain why this is and how I can fix this?

Thanks!
Cyranh
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, a few things to note... First, that just enabling the physics world will indeed cause issues if you haven't actually set up your instances to use physics and have fixtures etc... The physics system is completely different to the "regular" way of doing things and requires different functions to move and position objects. Second, using physics on a networked game could be problematic as the physics simulations will run differently on each machine... even if you set the same start conditions every time, due to the way Box2D does things, the results will be different: http://box2d.org/forum/viewtopic.php?t=9103
 

Cyranh

Member
Hi Nocturne. Thanks for responding :)

I have used the physics option before, but that worked fine when just enabling physics options in all the objects and setting the fixtures there without any code. What do I have to set up in code exactly? Just fixtures?

Secondly, the way the networking is set up, is that one player only sees sprites being drawn at the coordinates that it gets sent from the server. I understand that this means I have to do this with every object because you can't replicate forces the physics world. But in the way that I'm doing it, only the server has a physics world, and the clients are just seeing the sprites. This should be possible right?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
As long as the instances have fixtures (either within the object editor or through code) then enabling physics should work fine... if you are getting odd behaviours then we'd really need to see an example project or at least have the details of how things are set up. As for the networking thing, I'm no expert on the subject, but what you propose does indeed sound like it would work fine.
 

Cyranh

Member
If you download the LAN_Platformer demo that comes with GameMaker Studio and you enable the physics world in the game room, you'll see that every object with physics enabled will get stuck in the upper left corner. If you could let me know if you can replicate this, that would help out a lot. It could also be me bugging out, but I have tried it with several projects and I seem to be getting similar problems every time...
 

Yal

šŸ§ *penguin noises*
GMC Elder
There's a couple of things you can try...
  • Display physics variables (in particular position and velocity) for one object and see if it's physics coordinates seems fine. If it does, it might just be a visual bug, or a mismatch between the physics world pixel-per-meter size or something.
  • Use the physics debug drawing function to display all fixtures and forces and stuff and see if they match where the sprites are drawn.
Basically, there's two types of issues you might be seeing - either things are being physics'd correctly and drawn wrong, or they're physics'd wrong and drawn correctly. To find the issue, you need to know where to look, and being able to tell which of these two categories you're in is going to help a lot with that since you'll look in completely different places.
 

Cyranh

Member
@Yal As expected, that was it.
For some reason the demo file has pixels to meters set to 0. I did not check that, but that made the game trip pretty bad. No idea why that was set to 0.... weird.
It works now, sorry for the trouble! :)
 

Yal

šŸ§ *penguin noises*
GMC Elder
Great! :3 I didn't expect it to be zero (or that even being allowed), just maybe the wrong value.... but it's nice it was such an easy fix.
 
Top