I am trying to make a laser that will be visible to all clients in a multiplayer networked game on Unity.
I've tried using a Command Attribute but that hasn't worked. I also found some ideas to use RpcClient but I am not quite sure how to implement that.
The code I'm using for the laser (I just run the method in Update) is:
public void CmdActivateLaser(bool laserState)
{
if (laserState == false)
return;
pointer.SetPosition(0, transform.position);
RaycastHit endCommand;
if (Physics.Raycast(transform.position, transform.forward, out endCommand))
{
finalPos = new Vector3(0f, 0f, endCommand.distance);
pointer.SetPosition(1, finalPos);
}
else
{
pointer.SetPosition(1, transform.forward * 500f);
}
}
transform.forward * 500
is not necessarily a location that is 500 units in front of the object.transform.forward
is equal to(0,0,1)
multiplied by a rotation matrix. If you want a point that's actually 500 units in front of the transform, you need to add the transform's position,transform.position + transform.forward*500
\$\endgroup\$ – Draco18s no longer trusts SE Jul 13 '17 at 16:13