두 벡터 사이의 곡선이동
start 지점과 end 지점중 하나의 좌표가 0,0,0 이면 그냥 직선이동을 하는것 같다.
그래서 아래 함수 처럼 센터를 구한다음 센터의 값을빼고 다시 더해주는식으로 무조건 곡선이동을 할수 있게 하는듯.
선형보간법이라는게 참 어렵다..
Vector3.Slerp
Description
Spherically interpolates between two vectors.
Interpolates between
from and to by amount t. The difference between this and linear interpolation (aka, "lerp") is that the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated by the angle and its magnitude is interpolated between the magnitudes of from and to.t is clamped between [0...1]. See Also: Lerp function.using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public Transform sunrise; public Transform sunset; public float journeyTime = 1.0F; private float startTime; void Start() { startTime = Time.time; } void Update() { Vector3 center = (sunrise.position + sunset.position) * 0.5F; center -= new Vector3(0, 1, 0); Vector3 riseRelCenter = sunrise.position - center; Vector3 setRelCenter = sunset.position - center; float fracComplete = (Time.time - startTime) / journeyTime; transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete); transform.position += center; } }
'유니티 > 스크립트' 카테고리의 다른 글
| 적이 메인카메라 쪽 바라보게 하기 (0) | 2014.02.16 |
|---|---|
| 플레이어 가속도 주는 함수. (0) | 2014.02.13 |
| Vector3.Slerp 두 벡터 사이의 곡선 이동 (1) | 2014.02.06 |
| 자식오브젝트에서 부모 오브젝트 스크립트 실행 (0) | 2014.02.06 |
| OnMouseDown 및 List 활용한 이웃 블록 저장. (0) | 2014.02.06 |
| 큐브를 사용해서 커다란 보드 만들기. (0) | 2014.02.06 |
Trackback 0 And
Comment 1





