Jump to content

GeNa align object to spline


Lenar

Recommended Posts

Hi,

I need to align some objects along spline, as I understand I need to write my own GeNa spawn extension, but it's too difficult for me, I just want simple script to align object at spline node, with some parameters. 

1. How can I find any event on spline modified?

2. How to find node direction Node.Roll not working properly

    [SerializeField]
    Spline genaSpline;
    [field: SerializeField]
    public Spline GeNaSpline { get => genaSpline; private set => UpdateGeNaSpline(value); }

    [Range(0,100)]
    public int NodeID;
    public float XOffset;
    public float DistanceOffset;

    void UpdateGeNaSpline(Spline value)
    {
        //if new Spline assigned clear old dependencies, add listener to spline modify event 
        genaSpline = value;
        UpdatePosition();
    }

    void UpdatePosition()
    {
        if (!genaSpline) return;
        if (NodeID>=0 && NodeID<genaSpline.Nodes.Count)
        {
            GeNaNode node = genaSpline.Nodes[NodeID];
            Vector3 pos = node.Position;
            pos = pos+Quaternion.AngleAxis(node.Roll, Vector3.up) * Vector3.forward* XOffset;
            Terrain ter = Terrain.activeTerrain;
            if (ter)
            {
                TerrainCollider col = ter.GetComponent<TerrainCollider>();
                Ray ray = new Ray(pos + Vector3.up * 100f, Vector3.down);
                RaycastHit hit;
                if (col.Raycast(ray, out hit, 200f))
                {
                    pos = hit.point;
                }
            }
            transform.position = pos;
        }
    }

 

Link to comment
Share on other sites

            GeNaNode node = genaSpline.Nodes[NodeID];
            Vector3 pos = node.Position;
            GeNaCurve genaCurve = genaSpline.GetCurveFromNode(node);
            GeNaSample genaSample = genaCurve.GetSample(0.5f);
            pos = pos + genaSample.Right.normalized * NodeOffset;
            

So I found a solution for node offset, but still can't find event than spline is modified. please help, for now I just call UpdatePosition on Update

Link to comment
Share on other sites

Thanks @Manny, but this won't work after add/remove nodes. I think in this case I'd better leave it as it is and will call UpdatePosition on some time interval. Anyway thanks!

Link to comment
Share on other sites

How do I get a point between Node A and Node B? I thought it would be modifying the value of GetSample (normalized between 0 and 1) but it doesn't work, can you give me some extra hints please? 

genaCurve.GetSample(0.5f);
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...