seblague / path-creator Goto Github PK
View Code? Open in Web Editor NEWPath creation asset for Unity game development
Home Page: https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082
License: MIT License
Path creation asset for Unity game development
Home Page: https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082
License: MIT License
Hi there Seb and Keenan,
The ability to create a new path attached to an old path (branch) and join an existing path (merge) would be a really cool feature that would add a lot of value to this package. It could easily turn into an implementation nightmare if not properly constrained, but I think I have an approach that is simple enough to avoid increasing the complexity too much. I've already forked the project, and am working on implementing this now. This issue serves both as a design document and a request for feedback on the proposed additions.
A branch can be achieved manually by creating a new path and copying anchor/control pair from the original path into the first anchor/control pair for the new path. Similarly, a merge can be achieved by doing the same with the last anchor/control pair. Here's an example of the result.
Original Path:
Branching and Merging path:
The manual approach could be automated by allowing an anchor on one curve to reference an anchor on a different curve by providing the PathCreator and the index of the target anchor. Each anchor can only reference one other anchor (one parent), but each anchor might be the target of many references (many children). Each BezierPath now needs to keep track of each anchor's parent and children. Control points do not need to be kept track of like this because they are referenced implicitly by the anchors.
List<Tuple<BezierPath, int>> anchorsParent;
List<List<Tuple<BezierPath, int>>> anchorsChildren;
It would also be good to keep track of the relationships between BezierPaths:
Dictionary<BezierPath, Hashset<int>> pathIsParentAtAnchor;
Dictionary<BezierPath, Hashset<int>> pathIsChildAtAnchor;
One potential problem with this approach is that anchor indexes are not guaranteed to stay constant. Each child anchor needs to know when its parent path adds, splits, or removes a segment. Each parent anchor also needs to know when each child adds, splits, or removes a segment.
public event System.Action<BezierPath, int> OnAnchorAdded;
public event System.Action<BezierPath, int> OnAnchorRemoved;
When either of these events is triggered, the receiver should ensure that they they are referencing the same anchor they were before the event, or that they remove the reference if the anchor was removed. Changes can occur in one of three locations: upstream, downstream, or on each referenced index. An event downstream (higher index) of an anchor will not affect the anchor index and an event downstream (lower index) of an anchor will offset the anchor index by one. If an addition event coincides with a referenced anchor, increment its index. If a removal event coincides with a referenced anchor then remove all of the references to it.
Hey guys, how are you?
I'm trying to implement path walks for some npc in my game. I really don't like to much navmeshagent, I think it sucks actually. So I decided to take the harder but better way.
I am thinking if Path Creator is capable of moving as a rigid body, respecting the colliders and gravity it can be finding along the path.
Thanks!
As is, when I click on a point, I have no way of knowing its coordinates.
Could this be integrated with the Unity Inspector, so that these points can be moved around by changing the x, y, z coordinates in the Inspector (just like one can for everything else in Unity)?
Hi.
Thanks for the great spline tool. I have had some request for playmaker actions, so I have gone ahead and started making some. You can find them here: https://github.com/dumbgamedev/Path-Creator-PlaymakerActions
They are released under the MIT license.
Could you add a link to your description page or documentation, so that more users can find them?
Thank you 👍
First of all, thanks for the wonderful work, I am definitely gonna use it in the future even just to see these smooth movements maybe with a particle system.
Just some suggestions on some improvements:
Other suggestions on it would be any kind of parameter that can be interpolated like color, materials, scale.
Hello everyone,
I face a problem while I try to make my game object switch from one path to another using BoxCollider.
Here is some of the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PathCreation;
public class LandingOver : MonoBehaviour
{
public PathCreator Path2;
//Before this, my gameObject is following another path, let's call it Path1.
void OnTriggerEnter(Collider other)
{
other.gameObject.GetComponent<Follower>().pathCreator = Path2;
other.gameObject.GetComponent<Follower>().speed = 2f;
}
}
Unfortunately the gameObject switch from Path1 to Path2 but begin from the middle of Path2, not from the begining. So the transition is a fail. How to prevent my gameObject to "jump" ignoring a large part of Path2 ?
Do you have any other method to suggest ?
Thank you in advance for your time and consideration,
Francis
Could you add the option to set the starting point along the path (as distance from path's beginning point, i.e. offset), so that if multiple objects use the same path, they don't overlap?
Hey,
first thanks for you work, works great!!!
Is it possible to some how detect if a object has fully travelled the path?
I am looking for a way to count how many cycles an object travelled the path. I am using a non-looping setup.
I was thinking of doing it using the total path length and the travelled distance.
Is there a way to measure a paths length during run-time?
My first idea was to calculate the distance between all vertices of the vertex path.
Any more elegant way?
regards
Could you add an option to make the lines thicker, especially the normals?
As is, they are almost invisible when zoomed even slightly out.
PS: I am asking for thickness, not length (which you already have).
Hello there! First of all thanks a ton for this great tool.
I've upgraded from a previous version (1.0 or 1.1, not sure) via the asset store and I've noticed that GetClosestDistanceAlongPath is about 10-15 times slower compared to the previous implementation.
For many users this change might be negligible but in my use case I'm sampling the value of the curve over a grid hundreds of times.
What previously took around ~100 ms now jumped to ~1250 ms.
This is caused by the new world to local transformation enforced in GetPoint() for example.
While this can be helpful for many, it would be good to allow skipping the transformation when not necessary (for example my curves are already frozen at Pos=000, Rot=000, Scale=111) using a bool parameter transformToWorldSpace with a default value of true.
I'm developing a race car sims, i need to check end of path (race start line), it's possibile with path creator object or i need a collider object to solve the problem?
I got bad editor performance when using Path Creator inside Canvas. This canvas uses render mode Screen Space - Camera. Adding a new point make the performance worse.
I'm using Unity 2019.1.6.
It appears that moving a GameObject parent containing GameObject with a path has no affect on the path. Are there any plans to fix this or is there a work-around? For procedurally generated levels or placing paths in prefabs, this seems like a big problem.
How would this work when the object following the path is a camera?
I would like to have a camera move along the path, but also allow the player to control what direction the camera is looking into by using their mouse (Mouse Look).
How would you implement that?
So I know the mesh has a generate function, however adding the ability to use your own mesh and materials on the Road example would be very helpful for those looking for a free road tool replacement.
I may make a pull request in the future if I get it working properly.
Hi,
Here are three more example script that people may find helpful.
Thanks!
Eric
VertexPath.GetPointAtTime(1.0f) returns the start of the path instead of the end
while VertexPath.GetPointAtTime(0.9999f) is working correctly, and returns a point which is very near to the end of the curve.
I have the same result with VertexPath.GetPointAtDistance(VertexPath.length) which is not working either.
I'd love a callback in the editor when any spline properties/controls are changed.
Hello,
Recently on my main project when i create a pathcreator on a newly created GameObject the path isn't visible when the object is selected. This wasn't the case before and if i try to do the exact same thing on a new unity project it does work as expected.
Here is what i checked;
I can't find the difference between the two project so that it makes the path disapear. I spent 2 days searching for it.
I would thank anyone trying to help me. Here is also a .mp4 inside the zip folder to demonstrate the problem.
// First reflection
Vector3 offset = (localPoints[i] - localPoints[i - 1]);
float sqrDst = offset.sqrMagnitude;
Vector3 r = lastRotationAxis - offset * 2 / sqrDst * Vector3.Dot (offset, lastRotationAxis);
Vector3 t = localTangents[i - 1] - offset * 2 / sqrDst * Vector3.Dot(offset, localTangents[i - 1]);
// Second reflection
Vector3 v2 = localTangents[i] - t;
float c2 = Vector3.Dot (v2, v2);
Vector3 finalRot = r - v2 * 2 / c2 * Vector3.Dot (v2, r);
Vector3 n = Vector3.Cross (finalRot, localTangents[i]).normalized;
localNormals[i] = n;
lastRotationAxis = finalRot;
What does “first reflection” and “second reflection” mean?
Using 1.2 from GitHub.
Replication: create a path, scale it in either x, y or z using either the Transform component or tool, and observe that the whole path scales in the scene (x AND y AND z) even if only one of those axis is scaled in the transform.
The video shows this working as intended, where the path will stretch in the given axis (only) rather than scaling the whole thing.
Here's a video of the bug: https://streamable.com/3yg6d
I added the option to add a Meshcollider to the RoadMeshCreator.
Problem: You could simply add a meshcollider in the Unity editor. But if you do that, the meshcollider does not get updated when the mesh is altered by changing the path.
Solution: The skript attached takes care of updateing the meshcollider. Its very simple. Just enable the Meshcollider checkbox of the RoadMeshCreator Component.
I thought this feature could be intersing for others or even for trunk.
RoadMeshCreator.cs.zip
Is there a way to make it so the angle always points up? I am able to go through each point in the path and manually rotate it to get it to face upwards, but this takes a long time and it would be nice if I could just make the angle at all points always pointing up.
In other words... no banking, follower just always stays upright, doesn't tilt left or right
im trying to use pathCreator.path.GetPoint(1f)
to find the end of the path but I get the error Assets\Scripts\Follower.cs(30,59): error CS1503: Argument 1: cannot convert from 'float' to 'int'
As you can see in this debug log the selected point is slowly moving on it's own by .00003 in the Y and Z coordinates. The path was generated using the example generate path script and an array of vertices. The currentPosition and newPosition are reading the same change and staying equal so I'm not sure what could be causing it to slowly drift like that but it is sure slowing Unity to a crawl. Any thoughts what could be causing this?
If I were to press del while selecting the path, the path gets deleted, losing all the work.
Hi. Thank for the asset.
I'have encountered an issue. When I try to set anchor angle to first point of my new BezierPath from the last point of previous Bezier Path, the angles appears to be mirrored.
Here is the angle of last point of Bezier 1
And here is the angle of first point of Bezier 2 after setting the value from Bezier 1 angle
My code is:
path.bezierPath.SetAnchorNormalAngle(0, ZeroAngle());
float ZeroAngle()
{
return prevPath.bezierPath.GetAnchorNormalAngle(prevPath.bezierPath.NumAnchorPoints - 1);
}
Debug shows same values for angles.
Please help me with this issue.
Thank you.
Hello, at first, thank you so much for this asset, it's amazing!
But I have an issue with GetRotationAtDistance function. It returns slightly inaccurate values.
Here is an example:
I just instantiate objects in the right distance, and they have incorrect rotation in Z axis.
It would be great if you fixed it or tell me what I'm doing wrong :)
Maybe I'm missing something.
I have closed path, for some reason VertexPath.GetNormalAtDistance(0) return NaN vector. I assume it is not ok.
Hi, When I try to open the folder is not recognized as a Unity Project. Unity Version 2018.3.3
What's the best way to just create a straight line but still have it go through the Path Creator system?
I was curious if there were any plans to support manual type-in of path point positions? Specifically the start and end points for several paths we're using need to be set to a specific value.
Once you create the path, it never gets updated with the changes made on the gamobject's tranform. Normally, I would expect the changes on the game object's or its parents' transform changes to affect the path itself too. So it would be better if the created path's points were relative to the game object.
I think the tool is almost perfect and thank you for sharing it.
Hey Sebastian -
Great tool, thanks for sharing it!
When making a long path (many hundreds of units) the number of normals to calculate and draw was getting out of hand and slowing down the editor profoundly. Maybe consider not drawing each normal or showing every N where it's not doing too many?
for (int i = 0; i < normalsVertexPath.NumPoints; i++) { normalLines[i * 2] = normalsVertexPath.GetPoint (i); normalLines[i * 2 + 1] = normalsVertexPath.GetPoint (i) + normalsVertexPath.GetNormal (i) * globalDisplaySettings.normalsLength; }
Expected : The other Game Object is selected
Real result : The PathCreator is still selected
I believe this is not an expected behaviour and I can't find a workaround for this yet.
I was Wondering if it is possible to use the motion path controlled by timeline editor. It should be awesome for some movie scenes.
Hi! First of all thanks for this awesome tool it saved me a lot of time. Here's my issue :
I have a path creator and a roadMeshRenderer attached to a gameobject. I also have a script (separate game object) that gives a random position to a random number of points situated on the path when the game launches. For now it is working (the path is updated) only if I execute the game and, within the hierarchy, select the path creator component.
The problem here is that when I build the game I cannot access the hierarchy to update manually so how can I call some sort of UpdatePath() in an initialization method?
Thanks in advance :)
I need to load points from a script. Firstly I want to clear my path.
I tried to override all points via code:
var points = new Vector2[pathCreator.bezierPath.NumPoints];
for (var i = 0; i < pathCreator.bezierPath.NumPoints; i++) { points[i] = pathCreator.bezierPath.GetPoint(i); }
points[0] = Vector3.zero; // Some new value :)
var bezierPath = new BezierPath(points, false, PathSpace.xy);
pathCreator.bezierPath = bezierPath;
And I it doubled my Bezier points. If I run that code more times I have x4, x8 point count. I expect the same curve as it was before because with that code I don't change nothing.
And the second question is how to clear bezier points before settin' new values?
How to change a position of just one point of the Bezier path?
Hi Sebastian. Missing fragments of road when using RoadPathCreator. I have no idea why this happens. Normals hasn't been changed from code.
My player GameObject gets rotation (-1.06, 29.632, 4.346) at point (384.7814, 20.70795, 1509.418) and than sudden the player object rotations changes to (-1.057, 29.495, 89.72201) at point (386.1715, 20.76006, 1511.858).
Im using this code to position player:
player.transform.position = roadPath.GetPointAtTime(delta, EndOfPathInstruction.Stop);
player.transform.rotation = roadPath.GetRotation(delta, EndOfPathInstruction.Stop) * Quaternion.Euler(0, 0, 90);
Can you check what is wrong with path creator?
I can send you my unity project if you like.
My points are:
public Vector3[] pathPoints = new Vector3[] {
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(0.0f, 0.0f, 41.7f),
new Vector3(0.0f, 0.0f, 83.3f),
new Vector3(3.6f, 0.0f, 124.8f),
new Vector3(3.6f, 0.0f, 166.5f),
new Vector3(3.6f, 0.0f, 208.2f),
new Vector3(3.6f, 0.0f, 249.8f),
new Vector3(7.2f, -3.6f, 291.2f),
new Vector3(14.4f, -10.9f, 331.6f),
new Vector3(25.0f, -21.6f, 370.4f),
new Vector3(35.7f, -28.7f, 410.1f),
new Vector3(46.5f, -32.3f, 450.2f),
new Vector3(57.2f, -32.2f, 490.4f),
new Vector3(64.3f, -28.6f, 531.3f),
new Vector3(71.2f, -21.4f, 571.8f),
new Vector3(74.2f, -10.7f, 611.9f),
new Vector3(77.1f, 3.4f, 651.0f),
new Vector3(76.8f, 10.3f, 692.1f),
new Vector3(80.6f, 10.2f, 733.6f),
new Vector3(91.5f, 10.5f, 773.8f),
new Vector3(109.3f, 11.2f, 811.5f),
new Vector3(130.2f, 12.0f, 847.5f),
new Vector3(147.9f, 12.7f, 885.2f),
new Vector3(162.3f, 13.2f, 924.4f),
new Vector3(176.7f, 13.6f, 963.5f),
new Vector3(187.6f, 13.9f, 1003.7f),
new Vector3(195.0f, 14.0f, 1044.7f),
new Vector3(202.4f, 14.1f, 1085.7f),
new Vector3(206.1f, 14.1f, 1127.2f),
new Vector3(209.9f, 14.0f, 1168.7f),
new Vector3(210.1f, 13.7f, 1210.3f),
new Vector3(213.9f, 13.6f, 1251.8f),
new Vector3(224.8f, 13.9f, 1292.0f),
new Vector3(245.7f, 14.7f, 1328.1f),
new Vector3(275.3f, 16.1f, 1357.4f),
new Vector3(302.1f, 17.3f, 1389.2f),
new Vector3(326.1f, 18.3f, 1423.3f),
new Vector3(350.1f, 19.3f, 1457.3f),
new Vector3(374.1f, 20.3f, 1491.4f),
new Vector3(395.0f, 21.1f, 1527.4f),
new Vector3(416.0f, 22.0f, 1563.4f),
new Vector3(436.9f, 22.8f, 1599.4f),
new Vector3(457.9f, 23.7f, 1635.4f),
new Vector3(472.2f, 24.2f, 1674.5f),
new Vector3(479.6f, 24.3f, 1715.6f),
new Vector3(479.8f, 24.0f, 1757.2f),
new Vector3(479.9f, 23.7f, 1798.9f),
new Vector3(480.1f, 23.4f, 1840.6f),
new Vector3(482.5f, 19.1f, 2482.2f),
new Vector3(482.6f, 18.9f, 2523.9f),
new Vector3(482.8f, 18.6f, 2565.5f),
new Vector3(483.0f, 18.3f, 2607.2f),
new Vector3(483.1f, 18.0f, 2648.9f),
new Vector3(483.3f, 17.7f, 2690.5f)
};
Best regards
Peter
It would be grate to have tutorial on HOW TO MAKE RIGID BODY FOLLOW BESIER PATH. It's hard for me to do it.
So I'm building a procedural path using the tool and I have a test gameObject following the path and a sphere mesh as children with a script that changes its local x position. However sometimes the sphere goes through the path or flies above (only when local x is not 0 for a certain amount of time).
How can I fix that?
Thanks in advance!
When the space specified is on a 2-dimensional plane, the path snaps to the global 0 coordinate for the axis that is being ignored, rather than the local coordinate of the parent object. This means that if a user wants to create a path that is constrained to a 2-dimensional plane, they are obliged to do so in global space and then switch to 3d coordinates to move the path, rather than building the path in the parent transform's coordinate space. It also means the path jumps around quite a lot when the parent game object is far from the scene origin and a users is switching between path spaces.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.