Hello,
When I move on the minimap, it block my camera movement like if the restriction zone changed. It’s really annoying for the player because you could get stuck in a little square just because he used the Minimap once to move.
I tried to adapt my code several times by changing little details I still don’t see how the Minimap script is influencing the Camera Movement that much.
Here’s the Minimap code :
public class Minimap : MonoBehaviour, IPointerDownHandler, IDragHandler
{
[SerializeField] private RectTransform minimapRect = null; [SerializeField] private float mapScale = 20f; [SerializeField] private float offset = -7f; private Transform playerCameraTransform; private void Update() { if(playerCameraTransform != null) { return; } if(NetworkClient.connection?.identity == null) { return; } playerCameraTransform = NetworkClient.connection.identity.GetComponent<LDMPlayer>().GetCameraTransform(); } public void OnPointerDown(PointerEventData eventData) { MoveCamera(); } public void OnDrag(PointerEventData eventData) { MoveCamera(); } private void MoveCamera() { Vector2 mousePos = Mouse.current.position.ReadValue(); if(!RectTransformUtility.ScreenPointToLocalPointInRectangle(minimapRect, mousePos, null, out Vector2 localPoint)) { return;} Vector2 lerp = new Vector2((localPoint.x - minimapRect.rect.x)/minimapRect.rect.width, (localPoint.y-minimapRect.rect.y) /minimapRect.rect.height); Vector3 newCameraPos = new Vector3(Mathf.Lerp(-mapScale, mapScale, lerp.x), playerCameraTransform.position.y, Mathf.Lerp(-mapScale, mapScale, lerp.y)); playerCameraTransform.position = newCameraPos + new Vector3 (0f, 0f, offset); }
}
And here’s the Camera Movement script (I change it because the one from the course was absolutly not working and I had one working for a prvious game that I adapted for this one) :
public class CameraController : NetworkBehaviour
{
[SerializeField] private Transform playerCameraTransform = null; public float panSpeed = 20f; public float panBorderThickness = 10f; public Vector3 panLimit; public float scrollSpeed = 20f; public float minY = 10f; public float maxY = 120f; public override void OnStartAuthority() { playerCameraTransform.gameObject.SetActive(true); } public Transform GetTransform() { return playerCameraTransform; } [ClientCallback] private void Update() { if (!hasAuthority || !Application.isFocused) { return; } UpdateCameraPosition(); } private void UpdateCameraPosition() { Vector3 position = transform.position; if (Input.GetKey("z") || Input.mousePosition.y >= Screen.height - panBorderThickness) { position.z += panSpeed * Time.deltaTime; } if (Input.GetKey("s") || Input.mousePosition.y <= panBorderThickness) { position.z -= panSpeed * Time.deltaTime; } if (Input.GetKey("q") || Input.mousePosition.x <= - panBorderThickness) { position.x -= panSpeed * Time.deltaTime; } if (Input.GetKey("d") || Input.mousePosition.x >= Screen.width - panBorderThickness) { position.x += panSpeed * Time.deltaTime; } float scroll = Input.GetAxis("Mouse ScrollWheel"); position.y -= scroll * scrollSpeed * 100f * Time.deltaTime; position.x = Mathf.Clamp(position.x, -panLimit.x, panLimit.x); position.z = Mathf.Clamp(position.z, -panLimit.z, panLimit.z); position.y = Mathf.Clamp(position.y, minY, maxY); transform.position = position; }
}
Thanks in advance,
Fabvison