Exemplo n.º 1
0
        private IEnumerator SetNewDestination(bool useWait = true)
        {
            if (useWait && ShouldWeWait())
            {
                waiting = true;
                yield return(new WaitForSeconds(Random.Range(minWaitTime, maxWaitTime)));

                waiting = false;
            }

            var x = Random.Range(-randomMoveRadius, randomMoveRadius);
            var y = Random.Range(-randomMoveRadius, randomMoveRadius);

            destination = transform.position + new Vector3(x, y, 0f);
            lookAngle   = TransformUtils.LookAt(transform.position, destination);
        }
Exemplo n.º 2
0
        private void LookAtMouse()
        {
            var bodyPosition = body.position;
            var camDistance  = cam.transform.position.y - bodyPosition.y;
            var mouse        = cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, camDistance));

            var angle = TransformUtils.LookAt(transform.position, mouse);

            // Fixes a weird issue when its 180 that it does not show anything anymore
            if (Mathf.Abs(angle) > 179.9f && Mathf.Abs(angle) < 180.1f)
            {
                angle = 180.1f;
            }

            body.rotation = angle;
        }