Hello, i got the main camera following the players but once a player rotate to left or right the other player would do it too at the same time.
public override void OnStartLocalPlayer()
{
if (isLocalPlayer)
{
Camera.main.GetComponent<CameraFollowMultiplayer>().setTarget(gameObject.transform);
}
}
void Turning()
{
if (isLocalPlayer)
{
// Create a ray from the mouse cursor on screen in the direction of the camera.
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
// Create a RaycastHit variable to store information about what was hit by the ray.
RaycastHit floorHit;
// Perform the raycast and if it hits something on the floor layer...
if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
{
// Create a vector from the player to the point on the floor the raycast from the mouse hit.
Vector3 playerToMouse = floorHit.point - transform.position;
// Ensure the vector is entirely along the floor plane.
playerToMouse.y = 0f;
// Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
// Set the player's rotation to this new rotation.
playerRigidbody.MoveRotation(newRotation);
Debug.Log("Sending Hola to Server!");
Hola();
}
}
}
That is the player movement script.
public class CameraFollowMultiplayer : MonoBehaviour
{
// The position that that camera will be following.
public Transform playerTransform;
// The speed with which the camera will be following.
public float smoothing = 5f;
// reference to mini map camera object
public GameObject minimap;
// The initial offset from the target.
Vector3 offset;
void Start()
{
// Calculate the initial offset.
{
offset = transform.position - playerTransform.position;
}
}
void FixedUpdate()
{
// Create a postion the camera is aiming for based on the offset from the target.
{
Vector3 targetCamPos = playerTransform.position + offset;
// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
void Update()
{
if (Input.GetButtonDown("MiniMap"))
{
// Toggle minimap
minimap.SetActive(!minimap.activeInHierarchy);
}
if (playerTransform != null)
{
transform.position = playerTransform.position + offset;
}
}
public void setTarget(Transform target)
{
playerTransform = target;
}
}
That is the script attached to the main camera.
I noticed that the event happens on void Turning() (on the player movement script) Thanks in advance.
I am using Mirror networking.