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

スクリプト言語

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

CharacterController.velocity

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

Switch to Manual
public var velocity: Vector3;
public Vector3 velocity;
public velocity as Vector3

Description

キャラクターの相対的速度を返します。(注意点があります)

これはキャラクターが実際にどれだけ早く歩いているかを追跡することが可能です。例えば キャラクターが壁に張り付いた時にこの値は0 vectorになります。 注意: velocityは単に CharacterController.Move または CharacterController.SimpleMove の 呼び出し前後のタイムステップの差異を返します。 velocityはCharacterController外で起こったTransformの動きを追跡しないので相対的な値になります。 (例えばキャラクターの親が他のTransformの配下で 乗り物のようなもので移動する場合)

	function Update () {
		var controller : CharacterController = GetComponent(CharacterController);
		var horizontalVelocity : Vector3 = controller.velocity;
		horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
		
		// The speed on the x-z plane ignoring any speed 
		var horizontalSpeed : float = horizontalVelocity.magnitude;
		// The speed from gravity or jumping
		var verticalSpeed : float = controller.velocity.y;
		// The overall speed
		var overallSpeed : float = controller.velocity.magnitude;
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        Vector3 horizontalVelocity = controller.velocity;
        horizontalVelocity = new Vector3(controller.velocity.x, 0, controller.velocity.z);
        float horizontalSpeed = horizontalVelocity.magnitude;
        float verticalSpeed = controller.velocity.y;
        float overallSpeed = controller.velocity.magnitude;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Update() as void:
		controller as CharacterController = GetComponent[of CharacterController]()
		horizontalVelocity as Vector3 = controller.velocity
		horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z)
		horizontalSpeed as float = horizontalVelocity.magnitude
		verticalSpeed as float = controller.velocity.y
		overallSpeed as float = controller.velocity.magnitude