I've been tying to understand what the difference between these two methods of moving a rigid body are. Both seem to move the object at a constant rate and both operate on a RigidBody. So what's the difference between the two and when should one be used over the other?
Answer
transform.translate
is not going to utilize the physics system (doesn't look for collisions when moving, ignores any current velocity, etc.), nor will it nessesarily be smooth movement (since you can translate as far as you like). This is essentially setting a new location for the entire object, relative to the current position. This would be how you should move objects if you don't want to use physics. Either because the object doesn't have physics, or you want to ignore physics (like teleporting).
rigidbody.velocity
uses the physics system, and will be mostly smooth (except for extreme velocities). This is more like telling the objects which direction to move, instead of telling them what position be at. Movement here will consider the physics world around it. If you set a velocity towards a solid wall, the physics system will attempt to make that move, and adjust the velocity based on the collision with the wall. In many cases, you're more likely to leave the velocity alone and adjust the object's acceleration instead, likely by applying a force.
No comments:
Post a Comment