블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2735)
Unity3D (815)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-16 09:10

'Homing'에 해당되는 글 2건

  1. 2020.05.26 [Unity] 회전 없이 유도(Guided/Homing) 이동 로직
  2. 2011.05.04 유도탄
    /// <summary>
    /// 회전 없이 유도 이동만 하는 함수
    /// </summary>
    /// <param name="_trTarget">목표 지점</param>
    /// <param name="_v3CurrentDirection">현재 오브젝트가 이동할 방향</param>
    /// <returns></returns>
    IEnumerator Move_Guided(Transform _trTarget, Vector3 _v3CurrentDirection)
    {
        Transform trTarget = _trTarget;
        Vector3 v3TargetDirection = (trTarget.position - this.transform.position).normalized;
        Vector3 v3CurrentDirection = _v3CurrentDirection;
        if (v3CurrentDirection == Vector3.zero)
        {
            v3CurrentDirection = v3TargetDirection;
        }

        float fLookSpeed = 7f;
        float fMoveSpeed = 50f;
        float fAccumTime = 0f;

        while (0.01f < (this.transform.position - trTarget.position).sqrMagnitude)
        {
            // Rotate
            v3TargetDirection = (trTarget.position - this.transform.position).normalized;
            v3CurrentDirection = Vector3.RotateTowards(v3CurrentDirection, v3TargetDirection, Time.deltaTime * fLookSpeed, 0f);
            v3CurrentDirection = v3CurrentDirection.normalized;
            // Translate
            fAccumTime += Time.deltaTime * fMoveSpeed;
            this.transform.localPosition += (v3CurrentDirection * fAccumTime);
            yield return null;
        }

        yield return null;
        
        // 도착했으면 Destroy or Recycle
    }

 

보통 유도 기능 만들때 오브젝트 자체를 회전시키고, transform.forward 방향으로 Translate만 하면 됐는데

 

이번에는 유도 기능으로 이동만 하고 회전하지 않게 하기 위해서

Direction Vector를 따로 두고 Vector3.RotateTowards()를 사용해서 이동하게 만들었다.

 

P.s. 적당히 테스트 한거니 더 이쁘게 만들고 싶은분은 직접 수정 및 테스트 해보세요.

 

[참조] https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html

반응형
Posted by blueasa
, |

유도탄

Programming/Algorithm / 2011. 5. 4. 15:33
반응형

'Programming > Algorithm' 카테고리의 다른 글

lock free 알고리즘들...  (0) 2012.05.11
알고리즘의 설계  (0) 2010.04.14
Posted by blueasa
, |