Scripted Smooth Movement?

I am creating a channels-based control system for doors (don’t worry if you don’t understand that bit) and I have just got the script to move the attached object using:

this.gameObject.transform.position += Movement;

This, as expected, jumps to that position (or rather adds it on) but it is instantaneous, I am wondering if there is any way to do this with a smoother transition, like seeing it move, I don’t want to animate it as I want it to be quite quick to use and implement and will be using it in a lot of places.

You could try Vector3.MoveTowards,
so like:

this.gameObject.transform.positon = Vector3.MoveTowards(this.gameObject.transform.position, Movement, Time.deltaTime);

or

Vector3.Lerp (however this slows down as it gets closer to a value. So if you can get MoveTowards to work it’s probabaly better

this.gameObject.transform.positon = Vector3.Lerp(this.gameObject.transform.position, Movement, Time.deltaTime);

Interested what you mean by channels based control system though? Is there a link to an example?

These work great, I am going to use them both and have it as an option in an enum, but I have hit a snag.
Using the enum example from the Unity Tutorials:
https://unity3d.com/learn/tutorials/modules/beginner/scripting/enumerations

I have hit a problem, I cannot bring the enum over to the Update function (code below):

using UnityEngine;
using System.Collections;

public class GateScript : MonoBehaviour {

    public bool IsActive = true;
    public Vector3 Movement;
    public int BroadcastChannel;
    public enum Method { MoveTowards, Lerp };
    private GateControl[] ControlsPanels;

    void Start()
    {
        GateControl[] ControlsPanels = FindObjectsOfType(typeof(GateControl)) as GateControl[];
        Method MovementMethod;
    }

    void Update()
    {
        foreach (GateControl ControlPanel in ControlsPanels)
        {
            if (ControlPanel.BroadcastChannel == BroadcastChannel && ControlPanel.SignalSent)
            {
                this.gameObject.transform.position += Movement;
                if (MovementMethod == MoveTowards)
                {

                }
            }
        }
    }
}

I’m not the best with enums really but try declaring the Method MovementMethod outside of the start function with your other variables to make it global.

Then you need to say which type you want to check for, from which enum. (You could have many different enums in one script possibly with the same MoveTowards parameter. So you would use Method.MoveTowards

That would look like this:
(It also gives you a handy little drop down box in your inspector)

public enum Method { MoveTowards, Lerp };
public Method MovementMethod;

void Update()
{

if (MovementMethod == Method.MoveTowards)
{

}

}

Good luck

Managed to fix this in one area but broke another.
My way of looking for the objects giving off the correct channel used arrays has stopped working and I can now lo longer start without getting an “Array out of range” error.

using UnityEngine;
using System.Collections;

public class GateScript : MonoBehaviour
{
    public bool IsActive = true;
    public Vector3 Movement;
    public int BroadcastChannel;
    public enum Method { MoveTowards, Lerp };
    public Method MovementMethod = Method.MoveTowards;
    private GateControl[] ControlsPanels;

    void Start()
    {
        GateControl[] ControlsPanels = FindObjectsOfType(typeof(GateControl)) as GateControl[];
    }

    void Update()
    {
        foreach (GateControl ControlPanel in ControlsPanels)
        {
            if (ControlPanel.BroadcastChannel == BroadcastChannel && ControlPanel.SignalSent)
            {
                this.gameObject.transform.position += Movement;
                if (MovementMethod == Method.MoveTowards)
                {
                    this.gameObject.transform.position = Vector3.MoveTowards(this.gameObject.transform.position, Movement, Time.deltaTime);
                }

                if (MovementMethod == Method.Lerp)
                {
                    this.gameObject.transform.position = Vector3.Lerp(this.gameObject.transform.position, Movement, Time.deltaTime);
                }
            }
        }
    }
}

Try watching a few tutorials on areas you’re struggling in, and if you can’t solve it post a new question in forum or answers