Я пытаюсь создать круговой мир, в котором игрок может двигаться, код игрока:
public class Player : MonoBehaviour {
public float speed = 10f;
private Rigidbody rb;
private float horizontal = 0f;
private float vertical = 0f;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
horizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
vertical = Input.GetAxis("Vertical") * speed * Time.deltaTime;
}
private void FixedUpdate()
{
Vector3 origin = Vector3.zero;
Quaternion hq = Quaternion.AngleAxis(-horizontal, Vector3.up);
Quaternion vq = Quaternion.AngleAxis(vertical, Vector3.right);
Quaternion q = hq * vq;
rb.MovePosition(q * (rb.transform.position - origin) + origin);
transform.LookAt(Vector3.zero);
}
}
и работает отлично, сейчас я пытаюсь создать камеру, которая следует за игроком по кругумир, но не работает это:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class seguid : MonoBehaviour {
public Transform PlayerTransform;
private Vector3 _cameraOffset;
[Range(0.01f, 1.0f)]
public float SmoothFactor = 0.5f;
// Use this for initialization
void Start () {
_cameraOffset = transform.position - PlayerTransform.position;
}
// Update is called once per frame
void Update () {
Vector3 newPos = PlayerTransform.position + _cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPos, SmoothFactor);
}
}