GithubHelp home page GithubHelp logo

Comments (5)

banshee-gzzz avatar banshee-gzzz commented on August 18, 2024

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.

PavulonTwist avatar PavulonTwist commented on August 18, 2024

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.

banshee-gzzz avatar banshee-gzzz commented on August 18, 2024

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.

PavulonTwist avatar PavulonTwist commented on August 18, 2024

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.

banshee-gzzz avatar banshee-gzzz commented on August 18, 2024

ok, I'm glad you found a solution

from bgcurve.

Related Issues (19)

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.