The position of the transform in world space.
The position member can be accessed by the Game code. Setting this value can be used to animate the GameObject. The example below makes an attached sphere bounce by updating the position. This bouncing slowly comes to an end. The position can also be use to determine where in 3D space the transform.
#pragma strict // Use Transform.position to bounce a sphere. // The sphere and a quad are colored using materials. public class ExampleScript extends MonoBehaviour { var velocity: Vector3 = new Vector3(0.0f, 1.0f, 0.0f); var floorHeight: float = 0.0f; var sleepThreshold: float = 0.05f; var gravity: float = -9.8f; function Start() { transform.position = new Vector3(0.0f, 1.5f, 0.0f); } function FixedUpdate() { if (velocity.magnitude > sleepThreshold || transform.position.y > floorHeight) { velocity += new Vector3(0.0f, gravity * Time.fixedDeltaTime, 0.0f); } transform.position += velocity * Time.fixedDeltaTime; if (transform.position.y <= floorHeight) { transform.position = new Vector3(0.0f, floorHeight, 0.0f); velocity.y = -velocity.y; } } }
using UnityEngine;
// Use Transform.position to bounce a sphere. // The sphere and a quad are colored using materials.
public class ExampleScript : MonoBehaviour { Vector3 velocity = new Vector3(0.0f, 1.0f, 0.0f); float floorHeight = 0.0f; float sleepThreshold = 0.05f; float gravity = -9.8f;
void Start() { transform.position = new Vector3(0.0f, 1.5f, 0.0f); }
void FixedUpdate() { if (velocity.magnitude > sleepThreshold || transform.position.y > floorHeight) { velocity += new Vector3(0.0f, gravity * Time.fixedDeltaTime, 0.0f); }
transform.position += velocity * Time.fixedDeltaTime; if (transform.position.y <= floorHeight) { transform.position = new Vector3(0.0f, floorHeight, 0.0f); velocity.y = -velocity.y; } } }
Did you find this page useful? Please give it a rating: