Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bad rotation
#1
Exclamation 
hello
im trying to make a game like rush(https://play.google.com/store/apps/details?id=com.ketchapp.rush&hl=en_US)

but i have problem in implementing curvy road
my problem is that road have bad rotation (look at image)
https://img.onl/oSsD
   


it happens some times not all time

and this is image of my game(image)
https://img.onl/TQb96w
   

and this is how i insert segments

public void start_game()
    {
       
        mDir = Vector3.forward;
        last_x = 0;
        last_y = 0;
        for (int i = 0; i < cp_count_to_start; i++)
        {
            Vector3 p = TrackSpline.ControlPointsList[TrackSpline.ControlPointCount - 1].transform.localPosition;
            Vector3 position = TrackSpline.transform.localToWorldMatrix.MultiplyPoint3x4(p + mDir * cp_step_size);

// UnityEngine.Random.value => it float between 0 and 1
//DTUtility.RandomSign() => its float between -1 and 1

            float rndX = UnityEngine.Random.value * CurvationX * DTUtility.RandomSign();
            float rndY = UnityEngine.Random.value * CurvationY * DTUtility.RandomSign();
         
            mDir = Quaternion.Euler(rndX, rndY, 0) * mDir;

            CurvySplineSegment newControlPoint = TrackSpline.InsertAfter(null, position, true);

        }
        TrackSpline.Refresh();

        for (int i = 8; i < TrackSpline.ControlPointsList.Count; i++)
        {
            enemy g = Instantiate(enemy_prefab, TrackSpline.ControlPointsList[i].transform.position, Quaternion.identity).GetComponent<enemy>();
            g.gameObject.transform.rotation = Quaternion.LookRotation(TrackSpline.GetTangent(TrackSpline.ControlPointsList[i].TF));
            enemys.Add(g.gameObject);
        }
        Controller.Speed = 100;

        Controller.Play();
    }

  public void Track_OnControlPointReached(CurvySplineMoveEventArgs e)
    {
        if (e.ControlPoint.Distance > 10 * cp_step_size)
        {
            tranfer_to_end(enemys[0]);
            GameObject g = enemys[0];
            enemys.RemoveAt(0);
            enemys.Add(g);
        }
    }

public void tranfer_to_end(GameObject g)
    {

        float pos = Controller.AbsolutePosition;
        pos -= TrackSpline.ControlPointsList[0].Length;
        TrackSpline.Delete(TrackSpline.ControlPointsList[0], true);
        Vector3 p = TrackSpline.ControlPointsList[TrackSpline.ControlPointCount - 1].transform.localPosition;
        Vector3 position = TrackSpline.transform.localToWorldMatrix.MultiplyPoint3x4(p + mDir * cp_step_size);

        float rndX = UnityEngine.Random.value * CurvationX * DTUtility.RandomSign();
        float rndY = UnityEngine.Random.value * CurvationY * DTUtility.RandomSign();
   
        mDir = Quaternion.Euler(rndX, rndY, 0) * mDir;

        CurvySplineSegment newControlPoint = TrackSpline.InsertAfter(null, position, true);
        TrackSpline.Refresh();
        Controller.AbsolutePosition = pos;


        g.transform.position = newControlPoint.transform.position;
        g.transform.rotation = Quaternion.LookRotation(TrackSpline.GetTangentFast(newControlPoint.TF));

    }

PLZ HELP
Reply
#2
Hi
I see that your spline's orientation is set to Static. You can keep using this setting while setting the right rotation to the control points you create, or you can set the orientation to Dynamic. This way, only the rotation of the control points that are Orientation Anchors matters. More about it here:
https://curvyeditor.com/documentation/splines/curvysplinesegment#orientation_anchor
and here:
https://curvyeditor.com/documentation/splines/curvyspline#orientation
I hope this helped.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(11-22-2023, 11:45 PM)_Aka_ Wrote: Hi
I see that your spline's orientation is set to Static. You can keep using this setting while setting the right rotation to the control points you create, or you can set the orientation to Dynamic. This way, only the rotation of the control points that are Orientation Anchors matters. More about it here:
https://curvyeditor.com/documentation/splines/curvysplinesegment#orientation_anchor
and here:
https://curvyeditor.com/documentation/splines/curvyspline#orientation
I hope this helped.
Have a nice day

thank for reply
can you explain more?
my problem is bad rotation on my road that between 2 segments there is 180 degree turn(some times)!!!
maybe problem is my mesh generator

    void on_start()
    {
        mGenerators = new CurvyGenerator[1];

        for (int i = 0; i < mGenerators.Length; i++)
        {
            mGenerators[i] = buildGenerator();
            mGenerators[i].name = "Generator " + i;
        }

        for (int i = 0; i < mGenerators.Length; i++)
            while (!mGenerators[i].IsInitialized)
                yield return 0;
    }

CurvyGenerator buildGenerator()
    {
        // Create the Curvy Generator
        CurvyGenerator gen = CurvyGenerator.Create();
        gen.AutoRefresh = true;

        // Create Modules
        InputSplinePath path = gen.AddModule<InputSplinePath>();
        InputSplineShape shape = gen.AddModule<InputSplineShape>();
        BuildShapeExtrusion extrude = gen.AddModule<BuildShapeExtrusion>();
        BuildVolumeMesh vol = gen.AddModule<BuildVolumeMesh>();
        CreateMesh msh = gen.AddModule<CreateMesh>();
        // Create Links between modules
        path.OutputByName["Path"].LinkTo(extrude.InputByName["Path"]);
        shape.OutputByName["Shape"].LinkTo(extrude.InputByName["Cross"]);
        extrude.OutputByName["Volume"].LinkTo(vol.InputByName["Volume"]);
        vol.OutputByName["VMesh"].LinkTo(msh.InputByName["VMesh"]);
        // Set module properties
        path.Spline = TrackSpline;
        path.UseCache = true;
        CSRectangle rectShape = shape.SetManagedShape<CSRectangle>();
        rectShape.Width = 10;
        rectShape.Height = 1;
        extrude.Optimize = false;
        extrude.CrossHardEdges = true;
        vol.Split = false;
        vol.SetMaterial(0, road_material);
        vol.MaterialSetttings[0].SwapUV = true;
        vol.MaterialSetttings[0].KeepAspect = CGKeepAspectMode.ScaleV;
        msh.Collider = CGColliderEnum.None;
        return gen;
    }





some times my road and my spline path are not same
Reply
#4
Hi
The mesh generator is not the problem. The problem is from the orientation of the spline. To see what I am talking about, activate the display of the spline's orientation. To do so, go the toolbar, then the View Options, then tick "Orientation". Here is a video extract where this operation is done, plus more explanation about the orientation of splines.
https://www.youtube.com/watch?v=hHLdW_FRtfw&t=811s

So, based on what the gizmo displays, the orientation explanation in the tutorial and the documentation I shared in my earlier post, make sure your spline's control points are rotated properly to avoid the 180 rotation. I suggest to try to fix the spline first by hand, so you can visualize what's going on, and once you see what the issue is and what its fix is, then try to implement the fix in your spline generating code.

I hope this helped.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(11-23-2023, 09:02 PM)_Aka_ Wrote: Hi
The mesh generator is not the problem. The problem is from the orientation of the spline. To see what I am talking about, activate the display of the spline's orientation. To do so, go the toolbar, then the View Options, then tick "Orientation". Here is a video extract where this operation is done, plus more explanation about the orientation of splines.
https://www.youtube.com/watch?v=hHLdW_FRtfw&t=811s

So, based on what the gizmo displays, the orientation explanation in the tutorial and the documentation I shared in my earlier post, make sure your spline's control points are rotated properly to avoid the 180 rotation. I suggest to try to fix the spline first by hand, so you can visualize what's going on, and once you see what the issue is and what its fix is, then try to implement the fix in your spline generating code.

I hope this helped.
Have a nice day


i steel cant make it work

i changed the spline orientation to dynamic
and do this code  when adding new segment (SerializedOrientationAnchor = trueWink
and also set rotation to Zero(ControlPoint.SetRotation(quaternion.Euler(Vector3.zero))Wink

but steel i have to much rotation in my road ( maybe its becuae of tangents )

i want to limit that rotation of my road 

if you want to help me send some code man
thanks!
Reply
#6
Hi
Send me a reproduction case, meaning a project with all the necessary scripts, scenes and whatnot to reproduce the issue. I will then test it and see what is wrong.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rotation issue with generator nicolaj.h.andersen@gmail.com 1 14 04-14-2023, 11:58 AM
Last Post: _Aka_
Photo Rotation anchors tairoark 4 10 06-01-2022, 02:54 PM
Last Post: _Aka_
  Align to spline action and rotation Lupp_ 3 1,341 01-23-2021, 08:12 PM
Last Post: _Aka_
  Rotation of Curvy Spline Segment jh092 1 1,350 05-31-2020, 09:36 AM
Last Post: _Aka_

Forum Jump: