Как добавить к камере эффект орбиты? - PullRequest
0 голосов
/ 06 августа 2020

На моем плеере есть компоненты Animator, Rigidbody, Capsule Collider, скрипт управления пользователем от третьего лица, скрипт персонажа от третьего лица.

Player Settings

On the Main Camera there are two scripts but only one is activated for now : Camera Follow and Mouse Orbit With Zoom :

Main Camera Settings

The Camera Follow script is working fine. The problem is when I'm activating the Mouse Orbit With Zoom script if I move the player with the keys WASD and also rotate orbit the camera with the mouse the player lose focus. He does change his direction according to the mouse rotation but also lost focus :

Player lost focus when rotation camera

And also for some reason I can make the camera rotation to be diagonal:

диагональ

Причина, по которой основная камера не является дочерней по отношению к игроку, заключается в том, что она заставляет камеру заикаться и очень быстро вращаться на месте. Вот почему я добавил скрипт следования за камерой.

Скрипт следования за камерой:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform player;
    public Vector3 offset;

    // Update is called once per frame
    void Update()
    {
        transform.position = player.position + offset;
    }
}

Скрипт орбиты:

using UnityEngine;
using System.Collections;

[AddComponentMenu("Camera-Control/Mouse Orbit with zoom")]
public class MouseCameraOrbit : MonoBehaviour
{
    public Transform target;
    public float speed;

    private void Update()
    {
        if (Input.GetMouseButton(0))
        {
            transform.RotateAround(target.position,
                                            transform.up,
                                            -Input.GetAxis("Mouse X") * speed);

            transform.RotateAround(target.transform.position,
                                            transform.right,
                                            -Input.GetAxis("Mouse Y") * speed);
        }
    }
}

Моя игра относится к типу приключенческих игр и основная цель - сделать так, чтобы игрок двигался по клавишам, а также чтобы он мог смотреть вокруг, как по орбите с помощью мыши, потому что только следование за игроком не покажет, где находится go, поэтому я пытаюсь добавить орбиту .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...