https://www.youtube.com/watch?v=4HpC--2iowE
の動画をもとに三人称視点のカメラ移動、キャラクター移動を再現。
transformでの移動はObiropeがうまく動かないのでRigidBodyで移動させる必要があり対応させた。
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class move : MonoBehaviour
{
Rigidbody rb;
public float speed = 15.0f;
public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;
public Transform cam;
public float jumpSpeed = 15.0f;
// Start is called before the first frame update
void Start()
{
rb = this.GetComponent();
}
void Update()
{
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(x, 0f, z).normalized;
rb.AddForce(direction * speed);
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
rb.MoveRotation(Quaternion.Euler(0f, angle, 0f));
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
}
}
・最後のAddForceにTime.deltaTimeをかけたらダメ