Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating splines at run time
#3
Thanks so much, this is brilliant and working, one question though, is there a way I could show the spline without adding a control point so the player can see what the spline will look like before they click to place the control point? Would I need to add then remove the control point in the Update function continuously to achieve this effect? Or is there a better way that's perhaps less cpu intensive?

For anyone in the future the code to add a train track / road etc in runtime where you click the mouse is below, I just added an empty game object, put a CurvySpline component on it, I used a generator from the train demo that I had edited a bit (make sure the input spline paths are set to the new game object you made) and then add this script to the game object. Now I can make train tracks like in an sim/tycoon type game!

Code:
using UnityEngine;
using FluffyUnderware.Curvy;

public class TrackMaker : MonoBehaviour
{
    public CurvySpline track;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                track.Add(hit.point);
            }
        }
    }
}
Reply


Messages In This Thread
Creating splines at run time - by jamesunity - 07-16-2020, 08:35 AM
RE: Creating splines at run time - by _Aka_ - 07-16-2020, 10:47 AM
RE: Creating splines at run time - by jamesunity - 07-16-2020, 06:12 PM
RE: Creating splines at run time - by _Aka_ - 07-16-2020, 06:54 PM
RE: Creating splines at run time - by jamesunity - 07-16-2020, 07:40 PM
RE: Creating splines at run time - by _Aka_ - 07-16-2020, 08:02 PM
RE: Creating splines at run time - by jamesunity - 07-17-2020, 10:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Information New free asset: Converter For Unity Splines _Aka_ 5 18 04-25-2024, 11:11 AM
Last Post: _Aka_
  Help creating a wedge Thinkurvy 2 5 04-24-2024, 12:25 PM
Last Post: _Aka_
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_

Forum Jump: