言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Vector3.Slerp

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function Slerp(from: Vector3, to: Vector3, t: float): Vector3;
public static Vector3 Slerp(Vector3 from, Vector3 to, float t);
public static def Slerp(from as Vector3, to as Vector3, t as float) as Vector3

Description

球状に2つのベクトル間を補間します

fromfromto の間を補間します。この関数と、直線で補間する (別名 "leap")の違いは、ベクトルは方向としてではなく、空間の位置として扱われることです。 返されたベクトルの方向は角度によって補間され magnitudefromto の大きさの間で補間されます。 /t/ は [0...1]の間に制限されています。 See Also: Lerp 関数

	// Animates the position in an arc between sunrise and sunset.
	
	var sunrise : Transform;
	var sunset : Transform;
	
	// Time to move from sunrise to sunset position, in seconds.
	var journeyTime = 1.0;
	
	// The time at which the animation started.
	private var startTime: float;
	
	
	function Start() {
		// Note the time at the start of the animation.
		startTime = Time.time;
	}
	
	
	function Update () {
	    // The center of the arc
	    var center = (sunrise.position + sunset.position) * 0.5;
	    // move the center a bit downwards to make the arc vertical
	    center -= Vector3(0,1,0);
	
	    // Interpolate over the arc relative to center
	    var riseRelCenter = sunrise.position - center;
	    var setRelCenter = sunset.position - center;
	    
	    // The fraction of the animation that has happened so far is
	    // equal to the elapsed time divided by the desired time for
	    // the total journey.
	    var fracComplete = (Time.time - startTime) / journeyTime;
	    transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete);
	    transform.position += center;
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : 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;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public sunrise as Transform

	public sunset as Transform

	public journeyTime as float = 1.0F

	private startTime as float

	def Start() as void:
		startTime = Time.time

	def Update() as void:
		center as Vector3 = ((sunrise.position + sunset.position) * 0.5F)
		center -= Vector3(0, 1, 0)
		riseRelCenter as Vector3 = (sunrise.position - center)
		setRelCenter as Vector3 = (sunset.position - center)
		fracComplete as float = ((Time.time - startTime) / journeyTime)
		transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete)
		transform.position += center