부스터
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");
}
}
}
'유데미 강의 > C#과 Unity로 3D 게임 개발하기 : 부스트 프로젝트' 카테고리의 다른 글
소스 컨트롤 (0) | 2022.08.12 |
---|---|
오브젝트 회전과 매개변수와 Rigidbody (0) | 2022.08.04 |
클래스, Input 클래스 (0) | 2022.08.03 |
유니티 유닛 (0) | 2022.08.03 |
게임 디자인 - 부스트 프로젝트 (0) | 2022.08.03 |