SebLague / Path-Creator

Path creation asset for Unity game development
https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082
MIT License
1.83k stars 319 forks source link

Manually input position for a point? #110

Open Leprawel opened 3 years ago

Leprawel commented 3 years ago

I cant figure out how to do it, if Its possible. Having to move stuff by dragging points around with a mouse is not precise enough, I would like to input the position from keyboard.

mirgan commented 2 years ago

Yes, it's very inconvenient. I wrote a simple script that will help

[ExecuteInEditMode]
[RequireComponent(typeof(PathCreator))]
public class PathPoints : MonoBehaviour
{
    public bool active;
    public int index;
    public Vector3 position;

    private PathCreator _pathCreator;
    private int _lastIndex = -1;
    private void Awake()
    {
        _pathCreator = GetComponent<PathCreator>();
    }

    private void Update()
    {
        if (!active)
        {
            return;
        }

        if (index >= _pathCreator.bezierPath.NumPoints)
        {
            index = _pathCreator.bezierPath.NumPoints - 1;
        }

        if (index < 0)
        {
            index = 0;
        }

        if (_lastIndex != index)
        {
            position =  _pathCreator.bezierPath.GetPoint(index);
            _lastIndex = index;
        }
        _pathCreator.bezierPath.MovePoint(index, position);
    }
}