유니티 심화
플레이어 충돌 시 법선벡터(normal)방향으로 회전
송현호
2023. 8. 21. 13:04
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
this.rb.MovePosition(rb.position + this.transform.forward * Time.deltaTime);
}
private void OnCollisionEnter(Collision collision)
{
ContactPoint cp = collision.GetContact(0);
Quaternion rot = Quaternion.LookRotation(cp.normal);
this.transform.rotation = rot;
}
}