ํ์ฌ ์๋์ฐจ ๊ฒ์ ๊ฐ๋ฐํ ๋ คํ๋ ํ์์ธ๋ฐ ์ ๋ํฐ ์คํฌ๋ฆฝํ ์ด์บํ๋์ง ๊ฐ์ด ์์กํ์ ๊ทธ๋ฅ ์์ ์๋ฃ์ฐ๋ ์ค์
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class AxleInfo
{
ย ย public WheelCollider leftWheel;
ย ย public WheelCollider rightWheel;
ย ย public bool motor;
ย ย public bool steering;
}
public class SimpleCarController : MonoBehaviour
{
ย ย public List axleInfos;
ย ย public float maxMotorTorque;
ย ย public float maxSteeringAngle;
ย ย // finds the corresponding visual wheel
ย ย // correctly applies the transform
ย ย public void ApplyLocalPositionToVisuals(WheelCollider collider)
ย ย {
ย ย ย ย if (collider.transform.childCount == 0)
ย ย ย ย {
ย ย ย ย ย ย return;
ย ย ย ย }
ย ย ย ย Transform visualWheel = collider.transform.GetChild(0);
ย ย ย ย Vector3 position;
ย ย ย ย Quaternion rotation;
ย ย ย ย collider.GetWorldPose(out position, out rotation);
ย ย ย ย visualWheel.transform.position = position;
ย ย ย ย visualWheel.transform.rotation = rotation;
ย ย }
ย ย public void FixedUpdate()
ย ย {
ย ย ย ย float motor = maxMotorTorque * Input.GetAxis("Vertical");
ย ย ย ย float steering = maxSteeringAngle * Input.GetAxis("Horizontal");
ย ย ย ย foreach (AxleInfo axleInfo in axleInfos)
ย ย ย ย {
ย ย ย ย ย ย if (axleInfo.steering)
ย ย ย ย ย ย {
ย ย ย ย ย ย ย ย axleInfo.leftWheel.steerAngle = steering;
ย ย ย ย ย ย ย ย axleInfo.rightWheel.steerAngle = steering;
ย ย ย ย ย ย }
ย ย ย ย ย ย if (axleInfo.motor)
ย ย ย ย ย ย {
ย ย ย ย ย ย ย ย axleInfo.leftWheel.motorTorque = motor;
ย ย ย ย ย ย ย ย axleInfo.rightWheel.motorTorque = motor;
ย ย ย ย ย ย }
ย ย ย ย ย ย ApplyLocalPositionToVisuals(axleInfo.leftWheel);
ย ย ย ย ย ย ApplyLocalPositionToVisuals(axleInfo.rightWheel);
ย ย ย ย }
ย ย }
}
์ด ์ฝ๋์์ ์ฐจ ๊ฐ์๋ ์ค์ ํ๊ฒ ์ด์บ ๋ฐ๊ฟ?
๊ฐ์๋๋ฅผ ์ด๋ค์์ผ๋ก ์ค์ ํ๊ณ ์ถ์๊ฑด๋ฐ์?
๊ณ ์ํ๋ค...
๋ฌผ๋ฆฌ์์ด ํ ์ฝ๋ผ์ด๋๊ฐ ์์ง์๋๊ฐ??? rigidbody ์์ค๋ ์์ง์ด๋ ๋ชจ๋ฅด๊ฒ ๋ค...๊ฐ์๋ rigibody.addforce๊ฐ์ ์ค์ผํ์ง ์์๊น?
standard asset์ ์๋์ฐจ ํํ ๋ฆฌ์ผ ์์ด... ๊ทธ๊ฑฐ ๋ฏ์ด์ ๋ด๋ด
๊ฑฐ๊ธฐ ์๋์ฐจ ์คํฌ๋ฆฝํธ ์ ๋ถ ์ค๋ฅ๋์์ - dc App
์ด ?์ด์ ๋๋ค
ํผ์ง์ค ๋ฉํ ๋ฆฌ์ผ ์ด๋ฐ๊ฑด ๋ค๋ฃ์์?