Haxball Scripts

6 views
Skip to first unread message

Natalí Stibb

unread,
Aug 5, 2024, 11:30:02 AM8/5/24
to lornodeli
Mygame consists of two sphere (a player controlled sphere and an object sphere). Much like the game haxball, I am trying to write a script that applies a force or impulse to the other sphere when the player controlled sphere is both in contact with it, and the user pushes the space bar. I have attempted the following, but get no effect when I try it in the game.

Hi. I am making a game like haxball. I need to drag and shoot the ball but I have a problem, the ball doesn't act normal for the remote players. On the master client, the ball acts normal, while it acts weird on the remote players' screen. When the master client drags the ball, or shoots, the ball action is exactly how it has to be, but when I try to drag/shoot the ball the ball is weird. When I drag it, it is literally resisting against my player, the ball doesn't want to move, but it moves a bit, then resists again and moves again. I have seen some topics where we need to use something like PRC or something like this but I didn't get how to use it. Also I don't even know what the solution is right now. After days of work, I wanted to ask here finally. What should I do to sync the ball normally? I know lag and undeterministic physics matter but I know in this case I am doing something wrong, and I suppose these thing are not the main problem here. There must be something I haven't applied. So what should I do? Thanks in advance.


One player has control of the ball and sends the position updates. Everyone else is just using those updates when they come in and place the ball accordingly.

If you don't transfer ownership, the ball will act up, when used by anyone but the controller.


Actually yes, kind of. Since it is a 2d football game (like haxball) they will fight for the ball. I am stuck at this point for days. I don't know if you know haxball, but you can check it for a minute and then eventually you will get perfectly what I want/ask.


First I instantiated the ball rather than using it as a scene object, but it had some problems. First, the ball was appearing for the local player only and there was a ball for each client. After that I created a singleton script for 1 ball instance but it did not solve the problem that only the master client had a ball in its screen. The ball has photon view, transform view and rigidbody2d view components. Then I simply converted the ball to a scene object instead of a prefab. Now there is 1 ball but the movement is not perfect for each client. I was reading some topics and the documentation but I really didn't understand what I should do. Can you explain/show me what I have to do?


Explaining this here is sadly a bit out of scope as PUN 2 doesn't have the foundation to implement this interaction well. PUN does neither have a tick based engine (so input / reactions are imprecisely timed by definition), nor does it use the send rates I'd recommend for this kind of action.


You may want to look into Fusion. It has one authoritative client and this controls the physics. Everyone else is sending input and gets the results from the authority. This is a much better architecture for this case.


Disclaimer: Fusion is in beta currently. The APIs may still change and the docs are known to be lacking in detail and ease of use. Still, Fusion is a much better choice for this type of game, than PUN 2 is (where problems will show up much later in the development, when you polish synchronization).


It's not that simple. Physics need to run at high framerates and any delay and correction is very annoying and visible. So lag and network variance are hard to hide and the results get pretty unpredictable in many cases. Fusion syncs input to a host and the state back to all players. This is at least a consistent result.

3a8082e126
Reply all
Reply to author
Forward
0 new messages