Search Unity

How move something along a path?

Discussion in '2D' started by KhashayarJan, Jul 25, 2016.

  1. KhashayarJan

    KhashayarJan

    Joined:
    Jul 25, 2016
    Posts:
    12
    Hi

    I'm new to Unity. I have experience with SpriteKit.
    In SpriteKit, if I wanted to move something, I could use something like:
    let action = SKAction.moveTo( some point, duration: 4 seconds)
    myGameObject.runAction( action )​
    Then myGameObject would just move to the point and it would take 4 seconds.
    There's no need for coding in Update. Is there such a thing in Unity? Or I should always use update to move something.

    Also I could just create a CGPath ( an array of points, or a bezierPath) and use something like:
    let action = SKAction.moveAlongPath( some path, duration: 4 seconds)
    myGameObject.runAction( action )​
    And it would move along the path

    Is there a way to do this?
     
  2. KhashayarJan

    KhashayarJan

    Joined:
    Jul 25, 2016
    Posts:
    12
    What I want to do is throw a grenade in a 2D game and I want it to follow the same path.
    Something like throwing an arrow in tower defense game (like Kingdom Rush).
    I haven't seen a tutorial on throwing thing that would be the way I want it.
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    IMO the best tweening package for Unity is DOTween. There's a free version on the asset store. It has a path following tween.
     
    KhashayarJan likes this.
  4. KhashayarJan

    KhashayarJan

    Joined:
    Jul 25, 2016
    Posts:
    12
    Thank you
    I had no idea it's called Tweening
    Haven't tried it yet but based on the description it's exactly what I wanted.
     
    LiterallyJeff likes this.
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    KhashayarJan likes this.