0
\$\begingroup\$

If i want to use Physics in Unity2D what should be the most efficient way to move the object without interfering physics?

 1. Transform.position
 2. Rigidbody.Velocity
 3. Rigidbody.addForce
 4. Transform.translate
 5. Rigidbody.movePosition

Seems like there are a lot of ways and each way has a special purpose for when it should be used and when not. I just don't know that.

\$\endgroup\$
2

1 Answer 1

1
\$\begingroup\$

Modifying the velocity will interfere with your physics if you're not sure of what you're doing. Ideally, you'd move things around by adding forces. Using Rigidbody2D.AddForce is the least complicated way to move objects that have a RigidBody.

\$\endgroup\$
7
  • \$\begingroup\$ But when you constantly add force your object's speed goes on increasing how to maintain a constant speed? \$\endgroup\$ Commented May 2, 2016 at 19:59
  • \$\begingroup\$ Only add force until the speed is what you want, then stop adding force. \$\endgroup\$
    – House
    Commented May 2, 2016 at 20:01
  • \$\begingroup\$ It means we can't move at a constant velocity from rest, we'll have to accelerate to that velocity? \$\endgroup\$ Commented May 2, 2016 at 20:03
  • \$\begingroup\$ Yes, that's how physics works. There's no instantaneous changes in velocity. If you want to violate that, then you should change the velocity instead. But you'll need to account for any changes in the velocity the physics system makes, like drag, bouncing off other objects or walls, etc. You can also set a maximum velocity and have a very high acceleration. \$\endgroup\$
    – House
    Commented May 2, 2016 at 20:05
  • 1
    \$\begingroup\$ @evorlor, I guess you'd have to define 'interfere'. I'd say adding forces is supplying the physics system with inputs, not interfering. Thanks for commenting about your reason. \$\endgroup\$
    – House
    Commented May 3, 2016 at 5:50

Not the answer you're looking for? Browse other questions tagged .