force | In world coordinate system. |
Adds a force to the rigidbody.
Force can be applied only to an active rigidbody. If a GameObject is inactive, AddForce has no effect.
See Also: AddForceAtPosition, AddRelativeForce, AddTorque.
// Add a thrust force to push an object in its current forward // direction (to simulate a rocket motor, say). var thrust: float; var rb: Rigidbody;
function Start() { rb = GetComponent.<Rigidbody>(); }
function FixedUpdate () { rb.AddForce(transform.forward * thrust); }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public float thrust; public Rigidbody rb; void Start() { rb = GetComponent<Rigidbody>(); } void FixedUpdate() { rb.AddForce(transform.forward * thrust); } }
x | Size of force along the world x-axis. |
y | Size of force along the world y-axis. |
z | Size of force along the world z-axis. |
Adds a force to the rigidbody.
Force can be applied only to an active rigidbody. If a GameObject is inactive, AddForce has no effect.