как отключить rigidbody unity3d через скрипт

Rigidbody

class in UnityEngine

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.

Submission 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.

Description

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.

Properties

angularDragThe angular drag of the object.
angularVelocityThe angular velocity vector of the rigidbody measured in radians per second.
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.
detectCollisionsShould collision detection be enabled? (By default always enabled).
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.
inertiaTensorRotationThe rotation of the inertia tensor.
interpolationInterpolation allows you to smooth out the effect of running physics at a fixed frame rate.
isKinematicControls whether physics affects the rigidbody.
massThe mass of the rigidbody.
maxAngularVelocityThe maximimum angular velocity of the rigidbody measured in radians per second. (Default 7) range < 0, infinity >.
maxDepenetrationVelocityMaximum velocity of a rigidbody when moving out of penetrating state.
positionThe position of the rigidbody.
rotationThe rotation of the Rigidbody.
sleepThresholdThe mass-normalized energy threshold, below which objects start going to sleep.
solverIterationsThe solverIterations determines how accurately Rigidbody joints and collision contacts are resolved. Overrides Physics.defaultSolverIterations. Must be positive.
solverVelocityIterationsThe solverVelocityIterations affects how how accurately Rigidbody joints and collision contacts are resolved. Overrides Physics.defaultSolverVelocityIterations. Must be positive.
useGravityControls whether gravity affects this rigidbody.
velocityThe velocity vector of the rigidbody. It represents the rate of change of Rigidbody position.
worldCenterOfMassThe center of mass of the rigidbody in world space (Read Only).

Public Methods

AddExplosionForceApplies a force to a rigidbody that simulates explosion effects.
AddForceAdds a force to the Rigidbody.
AddForceAtPositionApplies force at position. As a result this will apply a torque and force on the object.
AddRelativeForceAdds a force to the rigidbody relative to its coordinate system.
AddRelativeTorqueAdds a torque to the rigidbody relative to its coordinate system.
AddTorqueAdds a torque to the rigidbody.
ClosestPointOnBoundsThe closest point to the bounding box of the attached colliders.
GetPointVelocityThe velocity of the rigidbody at the point worldPoint in global space.
GetRelativePointVelocityThe velocity relative to the rigidbody at the point relativePoint.
IsSleepingIs the rigidbody sleeping?
MovePositionMoves the kinematic Rigidbody towards position.
MoveRotationRotates the rigidbody to rotation.
ResetCenterOfMassReset the center of mass of the rigidbody.
ResetInertiaTensorReset the inertia tensor value and rotation.
SetDensitySets the mass based on the attached colliders assuming a constant density.
SleepForces a rigidbody to sleep at least one frame.
SweepTestTests if a rigidbody would collide with anything, if it was moved through the Scene.
SweepTestAllLike Rigidbody.SweepTest, but returns all hits.
WakeUpForces a rigidbody to wake up.

Messages

OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
OnCollisionExitOnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
OnCollisionStayOnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.

Inherited Members

Properties

gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

Static Methods

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeGets a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.

Copyright ©2021 Unity Technologies. Publication Date: 2021-10-05.

Источник

Rigidbody

как отключить rigidbody unity3d через скрипт. Inspector Rigidbody. как отключить rigidbody unity3d через скрипт фото. как отключить rigidbody unity3d через скрипт-Inspector Rigidbody. картинка как отключить rigidbody unity3d через скрипт. картинка Inspector Rigidbody. class in UnityEngine

Properties

Details

Parenting

When an object is under physics control, it moves semi-independently of the way its transform parents move. If you move any parents, they will pull the Rigidbody child along with them. However, the Rigidbodies will still fall down due to gravity and react to collision events.

Scripting

To control your Rigidbodies, you will primarily use scripts A piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary to add forces or torque. You do this by calling AddForce() and AddTorque() on the object’s Rigidbody. Remember that you shouldn’t be directly altering the object’s Transform when you are using physics.

Animation

For some situations, mainly creating ragdoll effects, it is neccessary to switch control of the object between animations and physics. For this purpose Rigidbodies can be marked isKinematic. While the Rigidbody is marked isKinematic, it will not be affected by collisions, forces, or any other part of the physics system. This means that you will have to control the object by manipulating the Transform component directly. Kinematic Rigidbodies will affect other objects, but they themselves will not be affected by physics. For example, Joints which are attached to Kinematic objects will constrain any other Rigidbodies attached to them and Kinematic Rigidbodies will affect other Rigidbodies through collisions.

Colliders

Colliders are another kind of component that must be added alongside the Rigidbody in order to allow collisions to occur. If two Rigidbodies bump into each other, the physics engine will not calculate a collision unless both objects also have a Collider attached. Collider-less Rigidbodies will simply pass through each other during physics simulation.

как отключить rigidbody unity3d через скрипт. RigidbodyandCollider. как отключить rigidbody unity3d через скрипт фото. как отключить rigidbody unity3d через скрипт-RigidbodyandCollider. картинка как отключить rigidbody unity3d через скрипт. картинка RigidbodyandCollider. class in UnityEngineColliders define the physical boundaries of a Rigidbody

Add a Collider with the Component->Physics menu. View the Component Reference page of any individual Collider for more specific information:

Compound Colliders

Compound Colliders are combinations of primitive Colliders, collectively acting as a single Rigidbody. They come in handy when you have a model that would be too complex or costly in terms of performance to simulate exactly, and want to simulate the collision of the shape in an optimal way using simple approximations. To create a Compound Collider, create child objects of your colliding object, then add a Collider component to each child object. This allows you to position, rotate, and scale each Collider easily and independently of one another. You can build your compound collider out of a number of primitive colliders and/or convex mesh colliders.

как отключить rigidbody unity3d через скрипт. CompoundCollider. как отключить rigidbody unity3d через скрипт фото. как отключить rigidbody unity3d через скрипт-CompoundCollider. картинка как отключить rigidbody unity3d через скрипт. картинка CompoundCollider. class in UnityEngineA real-world Compound Collider setup

In the above picture, the Gun Model GameObject has a Rigidbody attached, and multiple primitive Colliders as child GameObjects. When the Rigidbody parent is moved around by forces, the child Colliders move along with it. The primitive Colliders will collide with the environment’s Mesh Collider, and the parent Rigidbody will alter the way it moves based on forces being applied to it and how its child Colliders interact with other Colliders in the Scene.

Mesh Colliders can’t normally collide with each other. If a Mesh Collider is marked as Convex, then it can collide with another Mesh Collider. The typical solution is to use primitive Colliders for any objects that move, and Mesh Colliders for static background objects.

Note: Compound colliders return individual callbacks for each collider collision pair when using Collision Callbacks.

Continuous Collision Detection

Continuous collision detection is a feature to prevent fast-moving colliders from passing each other. This may happen when using normal (Discrete) collision detection, when an object is one side of a collider in one frame, and already passed the collider in the next frame. To solve this, you can enable continuous collision detection on the rigidbody of the fast-moving object. Set the collision detection mode to Continuous to prevent the rigidbody from passing through any static (ie, non-rigidbody) MeshColliders. Set it to Continuous Dynamic to also prevent the rigidbody from passing through any other supported rigidbodies with collision detection mode set to Continuous or Continuous Dynamic. Continuous collision detection is supported for Box-, Sphere- and CapsuleColliders. Note that continuous collision detection is intended as a safety net to catch collisions in cases where objects would otherwise pass through each other, but will not deliver physically accurate collision results, so you might still consider decreasing the fixed Time step value in the TimeManager inspector A Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary to make the simulation more precise, if you run into problems with fast moving objects.

Use the right size

If you are modeling a human make sure the model is around 2 meters tall in Unity. To check if your object has the right size compare it to the default cube. You can create a cube using GameObject > 3D Object > Cube. The cube’s height will be exactly 1 meter, so your human should be twice as tall.

If you aren’t able to adjust the mesh itself, you can change the uniform scale of a particular mesh asset by selecting it in Project View and choosing Assets->Import Settings… from the menu. Here, you can change the scale and re-import your mesh.

If your game requires that your GameObject needs to be instantiated at different scales, it is okay to adjust the values of your Transform’s scale axes. The downside is that the physics simulation must do more work at the time the object is instantiated, and could cause a performance drop in your game. This isn’t a terrible loss, but it is not as efficient as finalizing your scale with the other two options. Also keep in mind that non-uniform scales can create undesirable behaviors when Parenting is used. For these reasons it is always optimal to create your object at the correct scale in your modeling application.

Hints

2018–10–12 Page amended

Continuous Speculative collision detection method added in 2018.3

Источник

Rigidbody

Rigidbodies enable your GameObjects to act under the control of physics. The Rigidbody can receive forces and torque to make your objects move in a realistic way. Any GameObject must contain a Rigidbody to be influenced by gravity, act under added forces via scripting, or interact with other objects through the NVIDIA PhysX physics engine.

как отключить rigidbody unity3d через скрипт. Inspector Rigidbody. как отключить rigidbody unity3d через скрипт фото. как отключить rigidbody unity3d через скрипт-Inspector Rigidbody. картинка как отключить rigidbody unity3d через скрипт. картинка Inspector Rigidbody. class in UnityEngine

Properties

Property:Function:
MassThe mass of the object (in kilograms by default).
DragHow much air resistance affects the object when moving from forces. 0 means no air resistance, and infinity makes the object stop moving immediately.
Angular DragHow much air resistance affects the object when rotating from torque. 0 means no air resistance. Note that you cannot make the object stop rotating just by setting its Angular Drag to infinity.
Use GravityIf enabled, the object is affected by gravity.
Is KinematicIf enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform. This is useful for moving platforms or if you want to animate a Rigidbody that has a HingeJoint attached.
InterpolateTry one of the options only if you are seeing jerkiness in your Rigidbody’s movement.
NoneNo Interpolation is applied.
InterpolateTransform is smoothed based on the Transform of the previous frame.
ExtrapolateTransform is smoothed based on the estimated Transform of the next frame.
Collision DetectionUsed to prevent fast moving objects from passing through other objects without detecting collisions.
DiscreteUse discrete collision detection against all other Colliders in the Scene. Other colliders will use discrete collision detection when testing for collision against it. Used for normal collisions (This is the default value).
ContinuousUse Discrete collision detection against dynamic Colliders (with a Rigidbody) and sweep-based continuous collision detection against static Colliders (without a Rigidbody). Rigidbodies set to Continuous Dynamic will use continuous collision detection when testing for collision against this rigidbody. Other rigidbodies will use Discrete Collision detection. Used for objects which the Continuous Dynamic detection needs to collide with. (This has a big impact on physics performance, leave it set to Discrete, if you don’t have issues with collisions of fast objects)
Continuous DynamicUse sweep-based continuous collision detection against GameOjects set to Continuous and Continuous Dynamic collision. It will also use continuous collision detection against static Colliders (without a Rigidbody). For all other colliders, it uses discrete collision detection. Used for fast moving objects.
Continuous SpeculativeUse speculative continuous collision detection against Rigidbodies and Colliders. This is also the only CCD mode that you can set kinematic bodies. This method tends to be less expensive than sweep-based continuous collision detection.
ConstraintsRestrictions on the Rigidbody’s motion:-
Freeze PositionStops the Rigidbody moving in the world X, Y and Z axes selectively.
Freeze RotationStops the Rigidbody rotating around the local X, Y and Z axes selectively.

Details

The biggest difference between manipulating the Transform versus the Rigidbody is the use of forces. Rigidbodies can receive forces and torque, but Transforms cannot. Transforms can be translated and rotated, but this is not the same as using physics. You’ll notice the distinct difference when you try it for yourself. Adding forces/torque to the Rigidbody will actually change the object’s position and rotation of the Transform component. This is why you should only be using one or the other. Changing the Transform while using physics could cause problems with collisions and other calculations.

Rigidbodies must be explicitly added to your GameObject before they will be affected by the physics engine. You can add a Rigidbody to your selected object from Components->Physics->Rigidbody in the menu. Now your object is physics-ready; it will fall under gravity and can receive forces via scripting, but you may need to add a Collider or a Joint to get it to behave exactly how you want.

Parenting

When an object is under physics control, it moves semi-independently of the way its transform parents move. If you move any parents, they will pull the Rigidbody child along with them. However, the Rigidbodies will still fall down due to gravity and react to collision events.

Scripting

To control your Rigidbodies, you will primarily use scripts to add forces or torque. You do this by calling AddForce() and AddTorque() on the object’s Rigidbody. Remember that you shouldn’t be directly altering the object’s Transform when you are using physics.

Animation

For some situations, mainly creating ragdoll effects, it is neccessary to switch control of the object between animations and physics. For this purpose Rigidbodies can be marked isKinematic. While the Rigidbody is marked isKinematic, it will not be affected by collisions, forces, or any other part of the physics system. This means that you will have to control the object by manipulating the Transform component directly. Kinematic Rigidbodies will affect other objects, but they themselves will not be affected by physics. For example, Joints which are attached to Kinematic objects will constrain any other Rigidbodies attached to them and Kinematic Rigidbodies will affect other Rigidbodies through collisions.

Colliders

Colliders are another kind of component that must be added alongside the Rigidbody in order to allow collisions to occur. If two Rigidbodies bump into each other, the physics engine will not calculate a collision unless both objects also have a Collider attached. Collider-less Rigidbodies will simply pass through each other during physics simulation.

как отключить rigidbody unity3d через скрипт. RigidbodyandCollider. как отключить rigidbody unity3d через скрипт фото. как отключить rigidbody unity3d через скрипт-RigidbodyandCollider. картинка как отключить rigidbody unity3d через скрипт. картинка RigidbodyandCollider. class in UnityEngineColliders define the physical boundaries of a Rigidbody

Add a Collider with the Component->Physics menu. View the Component Reference page of any individual Collider for more specific information:

Compound Colliders

Compound Colliders are combinations of primitive Colliders, collectively acting as a single Rigidbody. They come in handy when you have a model that would be too complex or costly in terms of performance to simulate exactly, and want to simulate the collision of the shape in an optimal way using simple approximations. To create a Compound Collider, create child objects of your colliding object, then add a Collider component to each child object. This allows you to position, rotate, and scale each Collider easily and independently of one another. You can build your compound collider out of a number of primitive colliders and/or convex mesh colliders.

как отключить rigidbody unity3d через скрипт. CompoundCollider. как отключить rigidbody unity3d через скрипт фото. как отключить rigidbody unity3d через скрипт-CompoundCollider. картинка как отключить rigidbody unity3d через скрипт. картинка CompoundCollider. class in UnityEngineA real-world Compound Collider setup

In the above picture, the Gun Model GameObject has a Rigidbody attached, and multiple primitive Colliders as child GameObjects. When the Rigidbody parent is moved around by forces, the child Colliders move along with it. The primitive Colliders will collide with the environment’s Mesh Collider, and the parent Rigidbody will alter the way it moves based on forces being applied to it and how its child Colliders interact with other Colliders in the Scene.

Mesh Colliders can’t normally collide with each other. If a Mesh Collider is marked as Convex, then it can collide with another Mesh Collider. The typical solution is to use primitive Colliders for any objects that move, and Mesh Colliders for static background objects.

Note: Compound colliders return individual callbacks for each collider collision pair when using Collision Callbacks.

Continuous Collision Detection

Continuous collision detection is a feature to prevent fast-moving colliders from passing each other. This may happen when using normal (Discrete) collision detection, when an object is one side of a collider in one frame, and already passed the collider in the next frame. To solve this, you can enable continuous collision detection on the rigidbody of the fast-moving object. Set the collision detection mode to Continuous to prevent the rigidbody from passing through any static (ie, non-rigidbody) MeshColliders. Set it to Continuous Dynamic to also prevent the rigidbody from passing through any other supported rigidbodies with collision detection mode set to Continuous or Continuous Dynamic. Continuous collision detection is supported for Box-, Sphere- and CapsuleColliders. Note that continuous collision detection is intended as a safety net to catch collisions in cases where objects would otherwise pass through each other, but will not deliver physically accurate collision results, so you might still consider decreasing the fixed Time step value in the TimeManager inspector to make the simulation more precise, if you run into problems with fast moving objects.

Use the right size

If you are modeling a human make sure the model is around 2 meters tall in Unity. To check if your object has the right size compare it to the default cube. You can create a cube using GameObject > 3D Object > Cube. The cube’s height will be exactly 1 meter, so your human should be twice as tall.

If you aren’t able to adjust the mesh itself, you can change the uniform scale of a particular mesh asset by selecting it in Project View and choosing Assets->Import Settings… from the menu. Here, you can change the scale and re-import your mesh.

If your game requires that your GameObject needs to be instantiated at different scales, it is okay to adjust the values of your Transform’s scale axes. The downside is that the physics simulation must do more work at the time the object is instantiated, and could cause a performance drop in your game. This isn’t a terrible loss, but it is not as efficient as finalizing your scale with the other two options. Also keep in mind that non-uniform scales can create undesirable behaviors when Parenting is used. For these reasons it is always optimal to create your object at the correct scale in your modeling application.

Hints

2018–10–12 Page amended with editorial review

Continuous Speculative collision detection method added in 2018.3

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *