Skip to content

Commit

Permalink
#5 correction for position added
Browse files Browse the repository at this point in the history
  • Loading branch information
hani-sayegh committed Mar 23, 2017
1 parent e014442 commit ddf08cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Assets/Scripts/Dog/DogFP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ void Awake()
networkedInput = GetComponent<NetworkedInput>();

amI = GetComponent<NetworkingCharacterAttachment>();
GameState.disableControls = false;
//GameState.disableControls = false;
#endif
}

#if NETWORKING
float correctionTime = 3f;
float positionCorrectionTimer = 3f;
#endif
protected override void Update()
{
if (!controlsEnabled)
Expand All @@ -72,9 +76,19 @@ protected override void Update()
{
networkedInput.horizontal = Input.GetAxis("Horizontal");
networkedInput.vertical = Input.GetAxis("Vertical");
networkedInput.v = transform.position;
}
horizontal = networkedInput.horizontal;
vertical = networkedInput.vertical;
if (amI.clientsHost && positionCorrectionTimer < 0)
{
transform.position = networkedInput.v;
positionCorrectionTimer = correctionTime;
}
else
{
positionCorrectionTimer -= Time.deltaTime;
}
#else
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
Expand Down Expand Up @@ -205,8 +219,11 @@ private void RotateView()
m_MouseLook.LookRotation(transform, m_Camera.transform, networkedInput.xRot, networkedInput.yRot);
if (amI.host)
networkedInput.rotn = transform.rotation;

if (amI.clientsHost)
{
transform.rotation = networkedInput.rotn;
}
#else
float yRot = CrossPlatformInputManager.GetAxis("Mouse X");
float xRot = CrossPlatformInputManager.GetAxis("Mouse Y");
Expand Down
5 changes: 4 additions & 1 deletion Assets/hanisstuff/NetworkedInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ public class NetworkedInput : NetworkBehaviour
public Vector3 v;
//


//for rotation
[SyncVar]
public float yRot;
[SyncVar]
public float xRot;
[SyncVar]
public Quaternion rotn;

[SyncVar]
public bool crouch;
[SyncVar]
Expand Down

0 comments on commit ddf08cd

Please sign in to comment.