Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

Rigidbody

class in UnityEngine

/

Hereda de:Component

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual

Descripción

Control of an object's position through physics simulation.

Adding a Rigidbody component to an object will put its motion under the control of Unity's physics engine. Even without adding any code, a Rigidbody object will be pulled downward by gravity and will react to collisions with incoming objects if the right Collider component is also present.

The Rigidbody also has a scripting API that lets you apply forces to the object and control it in a physically realistic way. For example, a car's behaviour can be specified in terms of the forces applied by the wheels. Given this information, the physics engine can handle most other aspects of the car's motion, so it will accelerate realistically and respond correctly to collisions.

In a script, the FixedUpdate function is recommended as the place to apply forces and change Rigidbody settings (as opposed to Update, which is used for most other frame update tasks). The reason for this is that physics updates are carried out in measured time steps that don't coincide with the frame update. FixedUpdate is called immediately before each physics update and so any changes made there will be processed directly.

A common problem when starting out with Rigidbodies is that the game physics appears to run in "slow motion". This is actually due to the scale used for your models. The default gravity settings assume that one world unit corresponds to one metre of distance. With non-physical games, it doesn't make much difference if your models are all 100 units long but when using physics, they will be treated as very large objects. If a large scale is used for objects that are supposed to be small, they will appear to fall very slowly - the physics engine thinks they are very large objects falling over very large distances. With this in mind, be sure to keep your objects more or less at their scale in real life (so a car should be about 4 units = 4 metres, for example).

Variables

angularDragThe angular drag of the object.
angularVelocityThe angular velocity vector of the rigidbody.
centerOfMassThe center of mass relative to the transform's origin.
collisionDetectionModeThe Rigidbody's collision detection mode.
constraintsControls which degrees of freedom are allowed for the simulation of this Rigidbody.
detectCollisions¿Debería estar habilitada la detección de colisiones? (Por defecto siempre está habilitada).
dragThe drag of the object.
freezeRotationControls whether physics will change the rotation of the object.
inertiaTensorThe diagonal inertia tensor of mass relative to the center of mass.
inertiaTensorRotationLa rotación del tensor de inercia.
interpolationInterpolation allows you to smooth out the effect of running physics at a fixed frame rate.
isKinematicControla si las físicas afectan al rigidbody.
massLa masa del rigidbody.
maxAngularVelocityThe maximimum angular velocity of the rigidbody. (Default 7) range { 0, infinity }.
maxDepenetrationVelocityLa velocidad del rigidbody en el punto worldPoint en el espacio global.
positionLa posición del rigidbody.
rotationLa rotación del rigidbody.
sleepThresholdThe mass-normalized energy threshold, below which objects start going to sleep.
solverIterationCountAllows you to override the solver iteration count per rigidbody.
useConeFrictionForce cone friction to be used for this rigidbody.
useGravityControls whether gravity affects this rigidbody.
velocityEl vector velocidad del rigidbody.
worldCenterOfMassThe center of mass of the rigidbody in world space (Read Only).

Funciones Públicas

AddExplosionForceAplica una fuerza al rigidbody simulando el efecto de una explosión. La fuerza de la explosión disminuirá linearmente según aumente la distancia al rigidbody.
AddForceAplica un esfuerzo de torsión al Rigidbody.
AddForceAtPositionAplica una fuerza force en una posición position. Como resultado esto aplicará un esfuerzo de torsión y una fuerza en el objeto.
AddRelativeForceAplica al rigidbody una fuerza relativa a su sistema de coordenadas.
AddRelativeTorqueAplica al rigidbody una fuerza relativa a su sistema de coordenadas.
AddTorqueAplica un esfuerzo de torsión al Rigidbody.
ClosestPointOnBoundsEl punto más cercano al cubo delimitador de los Colliders adjuntos.
GetPointVelocityLa velocidad del rigidbody en el punto worldPoint en el espacio global.
GetRelativePointVelocityLa velocidad relativa del rigidbody en el punto relativePoint.
IsSleeping¿Está "durmiendo" el rigidbody?
MovePositionMueve el rigidbody a la posición position.
MoveRotationRota el rigidbody con una rotación rotation.
ResetCenterOfMassLa masa del rigidbody.
ResetInertiaTensorEl tensor de inercia se rota con inertiaTensorRotation.
SetDensitySets the mass based on the attached colliders assuming a constant density.
SleepObliga a un rigidbody a "dormir" al menos durante un frame.
SweepTestTests if a rigidbody would collide with anything, if it was moved through the scene.
SweepTestAllIgual que Rigidbody.SweepTest, pero devuelve todos los impactos.
WakeUpObliga a un rigidbody a "despertarse".

Mensajes

OnCollisionEnterOnCollisionEnter se llama cuando el Collider o Rigidbody entra en contacto con otro Collider o Rigidbody.
OnCollisionExitOnCollisionExit se llama cuando el Collider o Rigidbody ha dejado de tocar otro Collider o Rigidbody.
OnCollisionStayOnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.

Miembros heredados

Variables

gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagEl tag de este game object.
transformThe Transform attached to this GameObject (null if there is none attached).
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameEl nombre del objeto.

Funciones Públicas

BroadcastMessageLlama al método denominado methodName de todos los MonoBehaviour en este game objecto en cualquiera de sus hijos.
CompareTag¿Este game object está etiquetado con tag?
GetComponentDevuelve un componente de tipo type si el game object tiene a alguno adjuntado, o null si no lo tiene.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
SendMessageLlama al método denominado methodName en cada MonoBehaviour de este game object.
SendMessageUpwardsLlama al método denominado methodName en todos los MonoBehaviour de este juego y en todos los ancestros del behaviour.
GetInstanceIDReturns the instance id of the object.
ToStringDevuelve el nombre del objeto.

Funciones Estáticas

DestroyElimina un gameobject, componente o asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeDevuelve el primer objeto activo cargado de tipo type.
FindObjectsOfTypeDevuelve una lista de todos los objetos activos cargados de tipo type.
InstantiateDevuelve el nombre del objeto.

Operadores

bool¿Existe el objeto?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.