정주찬
2022. 8. 3. 16:30
부스터
RigidBody.AddRelativeForce(Vector3 vec)
상대적인 힘 (특정 개체의 좌표 혹은 변형 정보를 기반으로 힘을 가함)
RigidBody.AddForce(Vector3 vec)은 절대적인 힘 (월드좌표 기준)
Movement.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
private Rigidbody rigid;
[SerializeField]
private float mod = 100f;
void Start()
{
rigid = GetComponent<Rigidbody>();
}
void Update()
{
ProcessThrust();
ProcessRotation();
}
void ProcessThrust()
{
if (Input.GetKey(KeyCode.Space))
{
rigid.AddRelativeForce(Vector3.up * mod * Time.deltaTime); // Time.deltaTime은 1프레임당 시간
}
}
void ProcessRotation()
{
if (Input.GetKey(KeyCode.A))
{
Debug.Log("rotate left");
}
else if (Input.GetKey(KeyCode.D))
{
Debug.Log("rotate right");
}
}
}
