Unity/C# note

유니티 Rigidbody 노트

오발탄LAB 2021. 12. 7. 06:27
반응형

 RigidBody를 이용한 회전 

+ Radian을 구하는 것이 핵심

private void FixedUpdate()
{
Angle = AngleCalculator.GetAngle(this.transform.forward.x, this.transform.forward.z);
AngleDifference = (targetAngle.Angle - Angle);
}

public float GetAngle(floatx, floatz)
{
	float value = (float)((Mathf.Atan2(x,z) / System.Math.PI) * 180f);
    
    return value;
}

Mathf.Atan2

return the angle in radian between x , y 

지름을 arc로 변환시켰을 때의 곡선, 두변을 곡선과 연결시켰을 때의 각도

radius(red), same length, green angle 1 radian

 RigidBody Freeze 

 

 void InitRigidBody()
        {
            rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
            rb.mass = 1;
            rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;

            //rb.useGravity = false;
        }

 

 

 

 

 Rigidbody 프레임 속도 변경하기 

 

Edit > Project Settings > Time

※기본 fixed update의 프레임은 50프레임(Fixed Timestep 0.02) 정도이지만 게임의 프레임이 50보다 낮아지면 fixed update의 프레임도 자동으로 낮아진다. 

※ 1 ÷ 0.02 = 50 frame

 

반응형