유니티
회전 컨트롤하기
Nhahan
2022. 6. 11. 00:25
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] float torqueAmount = 1f;
Rigidbody2D rigidBody2D;
// Start is called before the first frame update
void Start()
{
rigidBody2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if(Input.GetKey(KeyCode.LeftArrow)) {
rigidBody2D.AddTorque(torqueAmount);
} else if (Input.GetKey(KeyCode.RightArrow)) {
rigidBody2D.AddTorque(-torqueAmount);
}
}
}
이과라면 알만한 torque가 나왔다... 엄청 어려웠었는데
rigidBody2D.AddTorque()의 파라미터로 값을 넣어주면 된다.
그리고 이를 [SerializedField]로 관리해서 편하게 조절할 수 있게 해주자.
728x90