본문 바로가기

Game/Unity

[unity3d]미사일터렛 + 자동 타켓팅 및 사격 AI

추가 스크립트
public Transform head;
public bool headRotate;
public float distance;
public float rotspeed=5;


다음 내용은 업데이트 함수 내에 추가.
distance = Vector3.Distance (Players.transform.position, transform.position);
Debug.DrawLine (head.transform.position, Players.transform.position,Color.yellow);
if (distance < 20)
{
fireon = true;
headRotate=true;
else
{
fireon = false;
headRotate=false;
}
if (headRotate) 
{
head.transform.rotation = Quaternion.Slerp(head.transform.rotation, Quaternion.LookRotation(Players.transform.position- head.transform.position), rotspeed * Time.deltaTime);
}


그 결과




http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial 이 홈페이지 튜토리얼 보고 거리재는 방법을 알아냈네요... 덕분에 일정 거리내에 타겟이 들어오는 경우에만 head가 회전하고, 사격할 수 있도록 AI를 구성할 수 있었습니다.


출처 : http://cafe.naver.com/unityhub

'Game > Unity' 카테고리의 다른 글

[unity3d]미사일 충돌 효과  (0) 2015.02.03
[unity3d]Tutorial  (0) 2015.02.03
[Unity3D]ChromaPack (Texture 압축 플러그인)  (0) 2015.02.02
[Unity3D]새로운 메카님(Mecanim)  (0) 2015.01.29
prime31 In App Billing plugin 설명  (6) 2015.01.29