Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question smoothstep and movetowards combination

Discussion in 'Scripting' started by melonhead, Jul 9, 2023.

  1. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    603
    i have an object that needs to rise on y axis and also move towards another object at the same time, the 2 lines are below

    transform.position = new Vector3(0, Mathf.SmoothStep(minimum, maximum, t), 0); // VERTICAL LIFT

    transform.position = Vector3.MoveTowards(transform.position, target.transform.position, step); // MOVE TOWARDS OBJECT

    i cant just use the move towards as the rising object has to reach its level while the move towards is still going then stay at the same y axis while still moving towards object

    if both lines are uncommented only the smoothstep works and the movetowards does not, is there a way to combine this into one working function?

    thank you
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,396
    Maybe use vector3.lerp?
     
  3. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    603
    cant believe the second i posted thread it occurs to me i am constantly setting x and z to 0. in the smoothstep, need to replace with transform.position.x and transform.position.z my bad brain
     
    DevDunk likes this.