Search Unity

Question: how to start slow, and then increase in speed based on distance.

Discussion in 'Scripting' started by crispysnore, Jul 3, 2022.

  1. crispysnore

    crispysnore

    Joined:
    Aug 2, 2016
    Posts:
    5
    My question is as above. How do I move an object starting slow and increasing the speed based on the distance to the target object?
    I'm using a mouseposition object for the target.
    I've tried using Vector3.Lerp but it only has a set speed at which it moves the desired object.
    I think i want a custom function like lerp but better, only I don't know how to make one.
     
  2. crispysnore

    crispysnore

    Joined:
    Aug 2, 2016
    Posts:
    5
    I can provide an example too by the way. this flash game alpha bounty uses the sort of function I'm talking about in it's move to mouse position code. https://kbhgames.com/game/alpha-bounty
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,935
  4. crispysnore

    crispysnore

    Joined:
    Aug 2, 2016
    Posts:
    5
    Thankyou that is exactly what i was looking for.