Machineboy空
화살의 head가 날아가는 방향으로 따라 회전 본문
//01. PlayerFire Script
public GameObject bulletFactory;
public Transform firePos;
private UpdateAttack()
{
var bullet = Instantiate(bulletFactory);
bullet.transform.position = firePos.position;
Vector3 dir = target.position - firePos.position;
bullet.transform.forward = dir + Vector3.up * 10;
}
==========================================================
//02. Bullet Script
Rigidbody rb;
public float speed = 10;
bool isHit;
Quaternion hitRotation;
Vector3 hitPos;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.velocity = transform.forward * speed;
}
void Update()
{
if(isHit)
{
transform.rotation = hitRotation;
transform.position = hitPostion;
}else
{
rb.transform.forward = rb.velocity.normalized;
}
}