Code Monkey home page Code Monkey logo

Comments (7)

YuudachiPoiii avatar YuudachiPoiii commented on September 23, 2024 2

Hi,

It took me time to understand how it works and I just discovered it today. It is indicated in the BezierPath script that the path between 2 points is created thanks to 4 points, 2 anchors and 2 control points which are in this order : [anchor1, control1, control2, anchor2]. There is a public function to edit the point at a certain index i. So here you just have to put the index 1 and 2 where you want to adjust the tangent !

Hope this solve your problem !

from path-creator.

YuudachiPoiii avatar YuudachiPoiii commented on September 23, 2024 1

I think he wants to change the point during runtime. To gather the position he wants to put the point he can still use raycast. By gathering the BezierPath (not the VertexPath !) and setting the Vector3 of the anchor to the correct index, he can create the shape he wants to.
taxi_yellow2.GetComponent<PathCreator>().bezierPath = bezierPath6; taxi_yellow2.GetComponent<PathCreator>().bezierPath.SetPoint(1,point_1,false); taxi_yellow2.GetComponent<PathCreator>().bezierPath.SetPoint(2,point_1,false);

For a 2 anchor point bezier curve, this code sets the control point of the two points at the same position.

from path-creator.

Oseryx avatar Oseryx commented on September 23, 2024

I need to change the control point positions at either end of an open path in real time. I didn't see any function for changing the position of control points in the documentation or anywhere in the code suggestions. Am I missing something?

there is no functions for this it's the Handles.FreeMoveHandle() function which is a unity editor function that makes gameobjects positioning easier it returns a Vector3 as result depending on mouse position

from path-creator.

Oseryx avatar Oseryx commented on September 23, 2024

I need to change the control point positions at either end of an open path in real time. I didn't see any function for changing the position of control points in the documentation or anywhere in the code suggestions. Am I missing something?

To change this you can use Handles.FreeMoveHandle() which is a unity editor function or use the Hanfles.PositionHandle() function which is also a function of the unity editor API and the cool thing about this function is having a transform tool when you click on the target point or object

from path-creator.

Oseryx avatar Oseryx commented on September 23, 2024

I think he wants to change the point during runtime. To gather the position he wants to put the point he can still use raycast. By gathering the BezierPath (not the VertexPath !) and setting the Vector3 of the anchor to the correct index, he can create the shape he wants to.
taxi_yellow2.GetComponent<PathCreator>().bezierPath = bezierPath6; taxi_yellow2.GetComponent<PathCreator>().bezierPath.SetPoint(1,point_1,false); taxi_yellow2.GetComponent<PathCreator>().bezierPath.SetPoint(2,point_1,false);

For a 2 anchor point bezier curve, this code sets the control point of the two points at the same position.

maybe but for this I recommend to have a bool that allows to still calculating bezier path when running because there is no interest of this only if the path changes when the game runs

from path-creator.

YuudachiPoiii avatar YuudachiPoiii commented on September 23, 2024

At each update, you can recreate a Bezier path with new list of waypoints or change only one using the previous code

from path-creator.

kirbyderby2000 avatar kirbyderby2000 commented on September 23, 2024

@YuudachiPoiii You are correct about manipulating the control points.

For anyone else trying to figure out how to manipulate control points through code, the constructor of the BezierPath won't directly let you manipulate the control points because it always defaults the control points into the "Automatic" control mode.

After you create a BezierPath via code, change ControlPointMode of your BezierPath to "Free" or "Mirrored". The index mapping of the points in a BezierPath is setup like this:
1st index = Anchor Point 1
2nd index = Control Point 1 (for Anchor 1)
3rd index = Control Point 2 (for Anchor 2)
4th index = Anchor Point 2
^ These would be the indices of the first segment of the bezier path. This structure repeats for additional segments starting with the same index the last segment ended with; so for example the indices of the points for your second segment are 4 - 7 with the 4th index = Anchor Point 2, 5th index = Control Point 3 (for Anchor 2), 6th index = Control Point 3 (for anchor 3), 7th index = Anchor Point 3.

You can check the values of the control points via GetPoint(int index), and then set the values via SetPoint(int index). You would use SetPoint() for the control point index of your choice using the index mapping structure mentioned.

from path-creator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.