Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to properly move a 2D object through script?

This is something that has confused me for a while and it's how to move an object through script without adding a force. This is useful because it would let me move an enemy up and then down to do a ground slam. So far I have just been adding an empty GameObject to where i want it to move and using MoveTowards however that gets pretty annoying so a way to do it fully in script would be much better. Thanks!


  • You could always do it by using Vector3.Lerp(startPos, endPos, percentToEndPosition). But I have been using the DoTween plugin recently and have nothing but positive things to say. It is very intuitive and has a lot of good documentation along with YouTube videos if video tutorials are more your style. If you wanted to move an enemy upwards the simplest way you would just say

    enemyGameObject.transform.DoMoveY(positionToMoveTo, timeToArrive);

    Plus they have lots of settings you can customize with transition smoothing, setting loops, and setting speed to constant as opposed to setting a time to arrive.

    Here is a link to their documentation (

    Link to unity plugin (

  • Okay, I'll try both Vector3.Lerp and DoTween, thanks for your help!

Sign In or Register to comment.