Vector3.Slerp 두 벡터 사이의 곡선 이동


두 벡터 사이의 곡선이동

start 지점과 end 지점중 하나의 좌표가 0,0,0 이면 그냥 직선이동을 하는것 같다.

그래서 아래 함수 처럼 센터를 구한다음 센터의 값을빼고  다시 더해주는식으로 무조건 곡선이동을 할수 있게 하는듯.

선형보간법이라는게 참 어렵다..


static Vector3 Slerp(Vector3 fromVector3 to, float t);

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;

Trackback 0 And Comment 1
  1. BlogIcon 2 2015.05.27 09:21 address edit & del reply