I'm making a small game for me and my friends. I am using Netcode to make the multiplayer part, but I don't understand why my players always aim at the same point on the screen.
So, what happen is that my player as a top down view, to aim the player as to put is cursor where the character should aim for. But the problem is when one of them rotate they all rotate...
the problem in images: https://imgur.com/a/CnGg28u
Here is my code for the aim part:
private (bool success, Vector3 position) GetMousePosition()
{
/*if (!IsOwner)
return (success: false, position: Vector3.zero);*/
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out var hitInfo, Mathf.Infinity, groundLayerMask))
return (success: true, position: hitInfo.point);
else
return (success: false, position: Vector3.zero);
}
private void Aim()
{
/*if (!IsOwner)
return;*/
var (success, position) = GetMousePosition();
if (success && !player.isDead)
{
Vector3 direction = position - transform.position;
direction.y = 0;
//Debug.Log($"ID:{OwnerClientId} {position}, {direction}");
isDebugAimPosition = true;
aimPosition = position + new Vector3(0, 1.5f, 0);
transform.forward = direction;
}
}
void Update()
{
if (!IsOwner)
return;
Aim();
}
And I got another problem that does not seem to be one... When a client join I got this error:
[Netcode] NetworkPrefab hash was not found! In-Scene placed NetworkObject soft synchronization failure for Hash: 3312273862!
it refers to my player prefab which is acting normal (except for the aim)... My player prefab is in the player prefab's slot of my network manager and in a network prefab list attached to the network manager too. I don't understand this one, but it seems harmless...
Thank for your time and precious help! Have a nice day
