hacasap
03-16-2010, 09:55 PM
Hello!
This is my first attempt at using replication. I've read quite a bit about replication and have an understanding of the basic concepts behind it. I have been trying to implement it for the first time and have been running into problems.
I have two variables, defined as such in MyPlayerController.uc:
var Repnotify Vector MouseHitWorldLocation;
var Vector PawnEyeLocation;
They are changed from my hud class based on the location of the mouse on the screen.
They are used in two functions in MyPlayerController:
function Rotator GetAdjustedAimFor( Weapon W, vector StartFireLoc )
{
local Rotator AimingRot;
local Vector AimingVect;
AimingVect = MouseHitWorldLocation - PawnEyeLocation;
AimingRot = Rotator(AimingVect);
`log("MPC: GetAdjustedAim on "@self@" is "@ROLE);
return AimingRot;
}
and
function UpdateRotation( float DeltaTime )
{
local Rotator newRotation;
local vector mousePosition;
mousePosition = MouseHitWorldLocation;
mousePosition.Z = MyPawn(Pawn).Location.Z;
NewRotation = rotator(mousePosition - MyPawn(Pawn).Location);
NewRotation.Pitch = 0;
if ( MyPawn(Pawn) != None )
MyPawn(Pawn).FaceRotation(NewRotation, deltatime);
}
Without any attempt at replicating the two variables, I noticed that UpdateRotation() works just fine for the player it runs on - server or client. Your own player will turn and face your cursor location. But I also noticed that on the screens that do NOT own the player, the player does not turn at all. This is not a huge deal right now, I suppose.
However, GetAdjustedAimFor() fails completely because MouseHitWorldLocation is (0,0,0) when this function runs. It was at this that I guessed that GetAdjustedAimFor() is called on the server (Which it is) and that MouseHitWorldLocation is only set on the client (Which it also is).
So I attempted to replicate MouseHitWorldLocation and PawnEyeLocation from the client to the server in this way:
replication
{
if ( ROLE == ROLE_AutonomousProxy )
MouseHitWorldLocation, PawnEyeLocation;
}
and to test to see if it replicates:
simulated event ReplicatedEvent(name Var)
{
if (Var == 'MouseHitWorldLocation')
{
`log("MHWL Replicated on: "@ROLE);
}
super.ReplicatedEvent(Var);
}
Yet GetAdjustedAimFor() still fails in the same way and I get no messages in the log like I should be if ReplicatedEvent() was being called on the replication of my variable.
This is my first attempt at trying to use replication so I really don't have any clues as to why this isn't working. If any more information is needed, just ask.
Thank you.
This is my first attempt at using replication. I've read quite a bit about replication and have an understanding of the basic concepts behind it. I have been trying to implement it for the first time and have been running into problems.
I have two variables, defined as such in MyPlayerController.uc:
var Repnotify Vector MouseHitWorldLocation;
var Vector PawnEyeLocation;
They are changed from my hud class based on the location of the mouse on the screen.
They are used in two functions in MyPlayerController:
function Rotator GetAdjustedAimFor( Weapon W, vector StartFireLoc )
{
local Rotator AimingRot;
local Vector AimingVect;
AimingVect = MouseHitWorldLocation - PawnEyeLocation;
AimingRot = Rotator(AimingVect);
`log("MPC: GetAdjustedAim on "@self@" is "@ROLE);
return AimingRot;
}
and
function UpdateRotation( float DeltaTime )
{
local Rotator newRotation;
local vector mousePosition;
mousePosition = MouseHitWorldLocation;
mousePosition.Z = MyPawn(Pawn).Location.Z;
NewRotation = rotator(mousePosition - MyPawn(Pawn).Location);
NewRotation.Pitch = 0;
if ( MyPawn(Pawn) != None )
MyPawn(Pawn).FaceRotation(NewRotation, deltatime);
}
Without any attempt at replicating the two variables, I noticed that UpdateRotation() works just fine for the player it runs on - server or client. Your own player will turn and face your cursor location. But I also noticed that on the screens that do NOT own the player, the player does not turn at all. This is not a huge deal right now, I suppose.
However, GetAdjustedAimFor() fails completely because MouseHitWorldLocation is (0,0,0) when this function runs. It was at this that I guessed that GetAdjustedAimFor() is called on the server (Which it is) and that MouseHitWorldLocation is only set on the client (Which it also is).
So I attempted to replicate MouseHitWorldLocation and PawnEyeLocation from the client to the server in this way:
replication
{
if ( ROLE == ROLE_AutonomousProxy )
MouseHitWorldLocation, PawnEyeLocation;
}
and to test to see if it replicates:
simulated event ReplicatedEvent(name Var)
{
if (Var == 'MouseHitWorldLocation')
{
`log("MHWL Replicated on: "@ROLE);
}
super.ReplicatedEvent(Var);
}
Yet GetAdjustedAimFor() still fails in the same way and I get no messages in the log like I should be if ReplicatedEvent() was being called on the replication of my variable.
This is my first attempt at trying to use replication so I really don't have any clues as to why this isn't working. If any more information is needed, just ask.
Thank you.