Replicating Mover

Discussions about Coding and Scripting
User avatar
comoestas
Average
Posts: 36
Joined: Tue Jan 04, 2011 12:33 am

Replicating Mover

Post by comoestas » Wed May 16, 2012 6:31 am

So I've been dealing with this headache called Mover.

I have the mover working fine for offline play. It's basically a square wall that can be rotated and positioned wherever and whenever needed(Pretty much static otherwise) As always, replication has got me. If I leave the mover as ROLE_SimulatedProxy, whenever a player approaches a mover, the mover rotates to its default rotation momentarily, and then switches back, as it gets updated by the server again. ROLE_DumbProxy solves the unwanted rotation, but produces unwanted lag, for example when player dodges up a sloped wall mover. It seems to me that frequently updating a DumbProxy mover by the server will cause some sort of frequent updating of the players collision with the mover on the client side.

I really just want the client to receive the mover, accept it as final for a long time(will be static until someone decides to move it), and so the server avoids replicating it many times, and both parties are happy with their smooth lag free static movers.

I've tried so much, now I'm just blindly searching in the dark.
Any help appreciated. :)

User avatar
Feralidragon
Godlike
Posts: 5120
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Replicating Mover

Post by Feralidragon » Wed May 16, 2012 9:33 am

Could you show your class/code?
I think simulated proxy is the way to go, the problem with the rotation may be the fact that replication of rotation is normalized and compressed when replicated to the client, or something in the client is resetting the rotation of the mover.

JackGriffin
Godlike
Posts: 3766
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Replicating Mover

Post by JackGriffin » Wed May 16, 2012 2:35 pm

Yeah, I'm interested in what problems you are having with this too. Depending on the slope degree dodging upwards sucks anyway so you might do a static test of the same pitch angle to exclude the mover being the issue.
Aside from that if you alter the mover's base properties you might create unintended consequences since a lot of other code has

Code: Select all

.IsA('Mover')
in it. If it were me, I'd make a custom actor here subclassed beside mover and assign it the traits you want.

I've never encountered this issue with movers myself. As long as the pitch remains low (relatively) there has never been movement issues that I've seen unless the mover itself was actually cycling at the moment.
So long, and thanks for all the fish

User avatar
comoestas
Average
Posts: 36
Joined: Tue Jan 04, 2011 12:33 am

Re: Replicating Mover

Post by comoestas » Thu May 17, 2012 12:57 am

or something in the client is resetting the rotation of the mover.
Precisely what I think is happening when I use SimulatedProxy. Further evidence is that it only does it when the player gets close enough to collide.

The code is pretty simple:

Code: Select all

class DynamicMover extends Mover
	native;
	
native function SetBrush(model m);

event PostBeginPlay()
{
	DesiredLocation = Location;
}

simulated function Tick(float DeltaTime)
{	
	if(Location != DesiredLocation) // REFUSE to move natively
		SetLocation(DesiredLocation);
}
	
defaultproperties
{
	 bNoDelete=false
}
Video of it (simulated proxy)(sorry for bad quality, my upload speed is crap):
[youtube]9F15a0nTvis[/youtube]

Side notes: Position where I was seemingly teleported to is (0, 0, 0). (I know this from previous experiments / SetLocation 0)
You can also see that the rotation is set to (0, 0, 0).

We must remember that this mover works perfectly fine offline. This mover will not move after being summoned.

JackGriffin
Godlike
Posts: 3766
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Replicating Mover

Post by JackGriffin » Thu May 17, 2012 1:59 am

You shouldn't summon a mover like this anyway. Not everything in a mover gets replicated and that's why it is messing up online. It's losing sync with the player. Movers in UT are bad enough anyway, I wouldn't give them an excuse to make it worse.

What effect are you trying to do? I can't really tell from the video. There looks like a bunch of better ways to do this though besides calling a mover into existence.
So long, and thanks for all the fish

User avatar
comoestas
Average
Posts: 36
Joined: Tue Jan 04, 2011 12:33 am

Re: Replicating Mover

Post by comoestas » Thu May 17, 2012 6:18 am

There is no better way to do it than calling a mover into existence. I need a solid wall that can be positioned and rotated, and that players can bump into, walk on, jump, dodge, etc. Trust me I've tried other ways. I went to the point of creating a custom collider class that would detect if its plane collided with the collision cylinder, and if so, push the actor out of the way. It worked well for upright walls, but when you tried to walk on them, physics was set to PHYS_Falling. Moving while on it, let alone jumping, was way beyond possibility using manual physics. Thus I sought to create actual geometry or dynamic BSP which is what movers are.

I have made this too perfect for offline play to give up on it now. In fact, it is mildly usable online as DumbProxy, if you don't mind collision lag when you get too close to it. But unfortunately, I mind and I guess most will mind in the game type I'll be using it in(shhh... its a secret).

Here is it working with dumb proxy(I created many walls, some invisible, minor detail. Note that it lags more on sloped walls):
[youtube]5KIcfyQ6u38[/youtube]
So if there is a suggestion to remedy this lag, or provide an alternative method, I would really appreciate it.

P.S. I can provide the full mod with source, I just ask that it not be revealed nor distributed to others.

User avatar
Feralidragon
Godlike
Posts: 5120
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Replicating Mover

Post by Feralidragon » Thu May 17, 2012 10:58 am

I loled at the simulated_proxy video, was quite funny seeing the bots bumping and see the mover have that weird behavior.

Anyway, without looking at the source (for now), perhaps the problem has to do with other default properties:

Code: Select all

MoverEncroachType=ME_ReturnWhenEncroach
NumKeys=2
MoveTime=1.000000
StayOpenTime=4.000000
InitialState=BumpOpenTimed
So, perhaps (and this is a wild guess for now), those properties are triggering unwanted mover behavior online when having things simulated in the client, therefore you may fix it (again, wild guess for now) by changing those properties to:

Code: Select all

MoverEncroachType=ME_IgnoreWhenEncroach
NumKeys=1
MoveTime=0.000000
StayOpenTime=0.000000
InitialState=""
Considering you set the RemoteRole to SimulatedProxy again.

JackGriffin
Godlike
Posts: 3766
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Replicating Mover

Post by JackGriffin » Thu May 17, 2012 12:32 pm

Considering the video you need to fix the collision problem first because that's unplayable. It won't be long spawning those before you create a trap area that player's get stuck in.

Why can't you switch from mock BSP and just use some sort of handmade mesh? Regardless you are going to need to create a better collision cylinder for it that keeps the player from getting trapped.

You should get with Ferali (first choice, he's by far the best coder helping people) or me privately and let one of us have what you are doing so we can see it directly. There's just a lot of guesswork on this end as to the end result you want. Either person you show it to is trustworthy and it will never go farther than what help you need before being deleted.
So long, and thanks for all the fish

User avatar
comoestas
Average
Posts: 36
Joined: Tue Jan 04, 2011 12:33 am

Re: Replicating Mover

Post by comoestas » Fri May 18, 2012 1:51 am

Thank you so much Ferali! When I put your suggestion into the default properties, simulated proxy worked, but lagged as much as the DumbProxy. Good thing I was reading up much on replication. Apparently the rotation and location values are compressed when replicated, loosing accuracy, and so the collision lag, or more appropriately, approximation error. To fix it, I replicated the separate components of both location and rotation as floats, and updated them in a simulated Tick. No accuracy loss and absolutely no lag, even with 200+ ping. Thanks to Ferali because without a SimulatedProxy, I would have no simulated Tick. :tu:

After making some polishes, I will give you guys the code if you're interested in seeing what you helped me out with. :wink:

JackGriffin
Godlike
Posts: 3766
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Replicating Mover

Post by JackGriffin » Fri May 18, 2012 2:39 am

Nice job. You ought to post some sample code along with the way you fixed it because I'm sure others have come across this too. It's already high in a google search.
So long, and thanks for all the fish

User avatar
comoestas
Average
Posts: 36
Joined: Tue Jan 04, 2011 12:33 am

Re: Replicating Mover

Post by comoestas » Fri May 18, 2012 4:43 am

Fully replicating mover code:

Code: Select all

class DynamicMover native;

var vector mDesiredLocation;
var rotator mDesiredRotation;
var float accLocX, accLocY, accLocZ, accRotYaw, accRotPitch, accRotRoll; // replicate without loosing accuracy

replication
{
	reliable if (Role == ROLE_Authority)
		accLocX, accLocY, accLocZ, accRotYaw, accRotPitch, accRotRoll;
}

native function SetBrush(model m);

event PostBeginPlay()
{
	mDesiredLocation = Location;
	mDesiredRotation = Rotation;
}

simulated function Tick(float DeltaTime)
{
	if(Role == ROLE_Authority)
	{
		accLocX = Location.X;
		accLocY = Location.Y;
		accLocZ = Location.Z;
		accRotYaw = Rotation.Yaw;
		accRotPitch = Rotation.Pitch;
		accRotRoll = Rotation.Roll;
	}
	else
	{
		mDesiredLocation.X = accLocX;
		mDesiredLocation.Y = accLocY;
		mDesiredLocation.Z = accLocZ;
		mDesiredRotation.Yaw = accRotYaw;
		mDesiredRotation.Pitch = accRotPitch;
		mDesiredRotation.Roll = accRotRoll;
	}

	if(Location != mDesiredLocation)
		SetLocation(mDesiredLocation);
	if(Rotation != mDesiredRotation)
		SetRotation(mDesiredRotation);
}

defaultproperties
{
	 bNoDelete=false
	 NetPriority=1.400000
	 MoverEncroachType=ME_IgnoreWhenEncroach
	 NumKeys=1
	 MoveTime=0.000000
	 StayOpenTime=0.000000
	 InitialState=""
}

JackGriffin
Godlike
Posts: 3766
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Replicating Mover

Post by JackGriffin » Fri May 18, 2012 5:07 am

So what is this for anyway? I've watched the vid and I still don't see what you are trying to do. Is this a sort of construction gun?
So long, and thanks for all the fish

User avatar
comoestas
Average
Posts: 36
Joined: Tue Jan 04, 2011 12:33 am

Re: Replicating Mover

Post by comoestas » Fri May 18, 2012 5:23 am

I have not much to reveal except that this will be a new team gametype. Best see my PM.

User avatar
Feralidragon
Godlike
Posts: 5120
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Replicating Mover

Post by Feralidragon » Fri May 18, 2012 11:14 am

No problem :)

As for the replication of vectors and rotators, yeah, they have that "problem" of being compressed:
- vectors: nearest int;
- rotators: they have a compression algorithm of their own;

So yeah, best thing to do in these cases where you need full precision is to put vectors in floats and rotators in ints (in the case of rotators int or float will have the same precision since the max precision of a rotator is an integer anyway), and then replicated them to the client, and let the client set them up on its own.

JackGriffin
Godlike
Posts: 3766
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Replicating Mover

Post by JackGriffin » Fri May 18, 2012 11:34 am

Man, I wish constructor guns were feasible in UT. I've spent a lot of time building with it when that was a popular 2k4 sub-group. People just went all out and made such elaborate palaces and building grounds. It was pretty cool and was a nice community to relax in.

I'm glad you got sorted out (Ferali is just the best) and that you posted up your fixes. You'll end up helping a lot of people doing that.
So long, and thanks for all the fish

Post Reply