Ejemplo n.º 1
0
        void FixedUpdate()
        {
            basicController.move(new Vector2(Input.GetAxis("Vertical"), -Input.GetAxis("Horizontal")));

            Vector3 controllerDir = new Vector3(Input.GetAxis("RightVertical"), 0, Input.GetAxis("RightHorizontal"));
            Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, camera.nearClipPlane + cursorDepth);

            detectInputType(controllerDir, mousePosition);

            if (inputType == InputType.CONTROLLER)
            {
                basicController.lookAt(controllerDir);
                crosshairInstance.SetActive(false);
            }

            if (inputType == InputType.KB)
            {
                crosshairInstance.SetActive(true);
                updateCrosshairPosition(mousePosition);
                RaycastHit hit;
                Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    Vector2 crosshairDir          = new Vector2(hit.point.x - transform.position.x, hit.point.z - transform.position.z);
                    float   rotationAngleToTarget = Vector3.SignedAngle(transform.forward, new Vector3(crosshairDir.x, 0, crosshairDir.y), Vector3.up);
                    basicController.rotate(rotationAngleToTarget);
                }
            }
        }
Ejemplo n.º 2
0
        void FixedUpdate()
        {
            Vector3 targetPosition    = target.position;
            Vector3 transformPosition = transform.position;
            Vector3 transformForward  = transform.forward;
            Vector3 transformRight    = transform.right;

            Vector2 direction     = new Vector2(targetPosition.x - transformPosition.x, targetPosition.z - transformPosition.z);
            float   rotationAngle = calculateRotationAngle(transformForward, direction, transformRight);

            basicController.rotate(rotationAngle);
            basicController.move(new Vector2(transformForward.x, transformForward.z));
        }