Comments (5)
Hi, no, we don't plan to add any new components or change API at the moment.
Regarding the object jumping around the point- could you try to add some angular threshold, so if it's around 90 (270) degrees, the object would stop?
Something like
var toMouse = mousePositionWorld - cursorPosition;
float dot = Vector3.Dot(tangent, toMouse.normalized);
if(dot<AngularThreshold){//do nothing, object is stopped}
else {//change cursor here}
will it work for you?
from bgcurve.
I'm not sure how angular threshold corresponds to the dot product AKA magnitude of vector of toMouse vector projected to tangent (normalized) vector.
Disregarding the fact that dot product has nothing to do with angle, the solution you suggested with a threshold doesn't fix the problem - it just stops cursor when the distance is too long. That even makes the problem worse as it additionally breaks cases when the user would move the object faster than the threshold lets you.
I've tried a couple of workarounds and improvements to that solution, but I've ended up in banging my head against a wall with a conclusion that different approach is needed.
If you don't plan any API changes I think I'll just implement point 2 myself as it seems to be stable, fast and easy enough.
we don't plan to add any new components or change API at the moment.
Does it mean that BGCurve won't be developed anymore? What are the plans for the project then? What should I do when I implement point 2 - Should I start new branch of this project?
from bgcurve.
As far as I understand, your issue is that your object does not stop at the projected point, but rather start jumping around it if the mouse cursor is far enough.
So I thought, you can calculate the angle between 2 vectors and if it's around 90 degrees, you simply stop the cursor, cause you can not decide, should you move it forward or backward, no matter how far the mouse cursor is.
Dot product is magnitudes of 2 vectors multiplied by the cosine of the angle between them.
So, in the example above, if you take dot product of 2 normalized vectors (tangent and toMouse are normalized), it should be around zero for angle around 90 degrees no matter how far the mouse cursor is (the condition has an error though, it should be if(Math.Abs(dot)<AngularThreshold)). You can use Vector2.Angle instead of dot as well.
So, it should stop the object as soon as this angle is around 90 degrees and it looks like it's much easier solution than any other option you mentioned. Or (it's also possible) that I do not understand what your task and issue really are.
At the moment, we do not plan to develop it further for many reasons, except bugs fixing, but if you want to merge your own changes for Math.getPositionByClosestPoint method, we'd appreciate it. Simply fork it and create a pull request.
from bgcurve.
Ah, now I understood your solution - ignoring of projections of almost perpendicular vectors which anyway result in small distances in projection.
In your description you used 2 normalized vectors. I wanted only tangent to be normalized to project on it full length of mousePos vector. When both vectors are normalized the issue is gone, but it introduces a lag when fast dragging (as I've desribed in my first comment).
Solution with only tangent normalized and ignoring projections of almost perpendicular vectors doesn't help as on sharp arcs the tangent changes it's angle quickly and for large distances to mouse it will make the projection technique useless as it will overshoot target (as we project on straight line and try to apply such distance on arc).
Nevertheless, that gave me an idea how to workaround that problem by mixing the check of almost perpendicular vectors with normalization of both vectors:
private void HandleDragging() {
Vector3 tangent;
Vector2 cursorPosition = cursor.Math.CalcPositionAndTangentByDistance(cursor.Distance, out tangent);
Vector2 mousePositionWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mouseDir = (mousePositionWorld - cursorPosition);
if (mouseDir.sqrMagnitude > 1.0f && Mathf.Abs(Vector2.Angle(tangent, mouseDir)) > 45.0f) {
mouseDir.Normalize();
}
float dot = Vector3.Dot(tangent, mouseDir);
float distanceDelta = Time.deltaTime * Mathf.Min(dot * speedMultiplier, maxSpeed);
cursor.Distance += distanceDelta;
}
This solution improves the situation when the arcs are smooth enough, but with very sharp arcs it still doesn't work, so I believe this approach cannot be used for general case and more sophisticated approach is needed. Anyway that could suffice for now. If better approach will be needed I will implement point 2 and I'll let you know with pull request about that :)
Thanks, for support!
from bgcurve.
ok, I'm glad you found a solution
from bgcurve.
Related Issues (19)
- Adding points dynamically. HOT 1
- Trigger Cursor Movement HOT 7
- point distance HOT 3
- BGCurve line render component osx / ios issue HOT 10
- Large distance between points and delay bug? HOT 2
- Manipulate multiple objects HOT 3
- Point controls coordinates problem HOT 1
- Get the interpolated value of a field at any position on the curve HOT 2
- Attached points as parent-child relation HOT 1
- Spawn GameObject along point of curve? HOT 2
- Cursor won't move after spawn 2 or more cursor by script. HOT 3
- Add parameter to Rotate component to control revolution around tangent
- Text is almost invisible in BGCurve Custom and System Fields when using Unity Professional Skin HOT 1
- breadboard logic simulator HOT 4
- Controlling path progress within Animation editor. HOT 5
- Incompatibility with Unity 2019.3.13f1+ HOT 4
- How can i convert absent curve to smooth (symmetry bezier) in runtime? HOT 2
- Missing type or namespace errors on build HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bgcurve.