Question by
Menelaos1996 · Aug 17, 2020 at 08:35 PM ·
rigidbodyvector3translateupdate function
Client RPC Question
Hello, I am new to C# and Unity and I am facing my first issue. I am trying to make a sphere translate on X,Y,Z Axis on a host and at the same time on a Client via mirror. The issue is that locally on the Host or on the Client I can see the Translation of the sphere normally on all 3 Axis (X,Y,Z) but from the Host to the Client (and the other way around) I can see only the Translation on the Z positive Axis. I am posting the code below.
public class AddPlayerControlledVelocity : NetworkBehaviour
{
public Rigidbody RB;
Vector3 xpForce;
Vector3 xnForce;
Vector3 zpForce;
Vector3 znForce;
Vector3 JumpForce;
[SerializeField]
KeyCode xkeyUp;
[SerializeField]
KeyCode xkeyDown;
[SerializeField]
KeyCode zkeyUp;
[SerializeField]
KeyCode zkeyDown;
[SerializeField]
KeyCode ykeyJump;
private void Start()
{
xpForce = new Vector3(+0.3f, +0, +0);
xnForce = new Vector3(-0.3f, +0, +0);
zpForce = new Vector3(+0, +0, +0.3f);
znForce = new Vector3(+0, +0, -0.3f);
JumpForce = new Vector3(+0, +0.5f, +0);
}
[Client]
void Update()
{
if (!hasAuthority)
return;
if (Input.GetKey(zkeyUp))
{
CmdMovezUp();
}
if (Input.GetKey(zkeyDown))
{
CmdMovezDown();
}
if (Input.GetKey(xkeyUp))
{
CmdMovexUp();
}
if (Input.GetKey(xkeyDown))
{
CmdMovexDown();
}
if (Input.GetKey(ykeyJump))
{
CmdMoveJump();
}
}
[Command]
private void CmdMovezUp()
{
RpcMovezUp();
}
private void CmdMovezDown()
{
RpcMovezDown();
}
private void CmdMovexUp()
{
RpcMovexUp();
}
private void CmdMovexDown()
{
RpcMovexDown();
}
private void CmdMoveJump()
{
RpcMoveJump();
}
[ClientRpc]
private void RpcMovezUp() => RB.velocity += zpForce;
private void RpcMovezDown() => RB.velocity += znForce;
private void RpcMovexUp() => RB.velocity += xpForce;
private void RpcMovexDown() => RB.velocity += xnForce;
private void RpcMoveJump() => RB.velocity += JumpForce;
}
Thanks in advance.
Comment