Moving Objects in Unity The Right Way

Physics based

Rigidbody SetVelocity
rb.velocity = transform.forward;
Once velocity is set provided there is no drag object will maintain pace until collision.
Great for launching an object with a speed independent of its mass

Rigidbody MovePosition
r…


This content originally appeared on DEV Community and was authored by EliteSalad

Physics based

Rigidbody SetVelocity
rb.velocity = transform.forward;
Once velocity is set provided there is no drag object will maintain pace until collision.
Great for launching an object with a speed independent of its mass

Rigidbody MovePosition
rb.MovePosition(transform.position + (transform.forward * Time.deltaTime));
Only physics based way to move a kinematic object
Stable Way to move a rigidbody object without manipulating the physics of the object just the position.

Rigidbody AddForce
rb.AddForce(transform.foward * Time.deltaTime );
Every frame force will be added leading to acceleration up to infinity provided drag is 0.
Allows for specific force modes to be inserted such as Start, Impulse, Acceleration, Force, and Velocity Change. These can all change the behavior of how that particular force is applied to the object.

Position Based

Transform Translate
transform.Translate(Vector3.foward * Time.deltaTime);
Gives an amount of space to move each frame
Great for animating
Can move kinematic objects

Transform Set Position
transform.position += transform.forward * Time.deltaTime;
Giving new position to move every frame
Great for animating
Can move kinematic objects

Because movement operations through transform happen asynchronously when moving through or next to an object with a collider on the object may bounce or stutter as it tries to continue in the desired direction. This is because it successfully moves before being rejected back out by the physics of the collider. Because of this using these functions on an object that is meant to touch another object in some way is not recommended.


This content originally appeared on DEV Community and was authored by EliteSalad


Print Share Comment Cite Upload Translate Updates
APA

EliteSalad | Sciencx (2021-11-28T23:05:40+00:00) Moving Objects in Unity The Right Way. Retrieved from https://www.scien.cx/2021/11/28/moving-objects-in-unity-the-right-way/

MLA
" » Moving Objects in Unity The Right Way." EliteSalad | Sciencx - Sunday November 28, 2021, https://www.scien.cx/2021/11/28/moving-objects-in-unity-the-right-way/
HARVARD
EliteSalad | Sciencx Sunday November 28, 2021 » Moving Objects in Unity The Right Way., viewed ,<https://www.scien.cx/2021/11/28/moving-objects-in-unity-the-right-way/>
VANCOUVER
EliteSalad | Sciencx - » Moving Objects in Unity The Right Way. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/28/moving-objects-in-unity-the-right-way/
CHICAGO
" » Moving Objects in Unity The Right Way." EliteSalad | Sciencx - Accessed . https://www.scien.cx/2021/11/28/moving-objects-in-unity-the-right-way/
IEEE
" » Moving Objects in Unity The Right Way." EliteSalad | Sciencx [Online]. Available: https://www.scien.cx/2021/11/28/moving-objects-in-unity-the-right-way/. [Accessed: ]
rf:citation
» Moving Objects in Unity The Right Way | EliteSalad | Sciencx | https://www.scien.cx/2021/11/28/moving-objects-in-unity-the-right-way/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.