0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

3Dキャラクターを追従するカメラとカメラアングルに応じた移動をする

Last updated at Posted at 2021-05-06

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をかけたらダメ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?