Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make it work with physics (rapier) and gravity? #83

Open
pierroo opened this issue Jul 24, 2024 · 5 comments
Open

How to make it work with physics (rapier) and gravity? #83

pierroo opened this issue Jul 24, 2024 · 5 comments

Comments

@pierroo
Copy link

pierroo commented Jul 24, 2024

I am trying to make a vehicle wandering all over the navmesh randomly.

However the navmesh isn't just a flat plane, but has lot of ups and downs etc.

Every docs and examples and codepen I find online using Yuka are having super simple and flat navmesh; so navigating along a slope or mountain is never a question.

So I was thinking to apply Yuka on a Rigidbody from rapier to at least have the gravity and make sure the vehicle is constantly touching ground, but it's a nightmare to manage force applied etc.

Is there a way to make sure a vehicle follows the NavmeshConvex including its y position?

EDIT: unless I raycast from every vehicle inside their useframe toward under them and adjust their y position accordingly, but this sound like a very heavy query on each frame no?

@Mugen87
Copy link
Owner

Mugen87 commented Jul 24, 2024

In the following official demo, the nav mesh isn't flat:

https://mugen87.github.io/yuka/examples/navigation/navmeshPerformance/

You can use the standard FollowPathBehavior steering behavior for this use case.

@pierroo
Copy link
Author

pierroo commented Jul 25, 2024

Thank you for this great link once again.
Is there a way to see the code of this example?

On the other hand, we can see the convex region aren't perfectly aligned to the underlying model:
image

is there a parameter when creating the navmeshconvexregion to reduce the precision of it so I could have less region for better performance on my end?
I have a smaller map than this example, but 10 times more regions, obviously because of the number of triangles underneath but if there is a way to adjust that would be great as well

@Mugen87
Copy link
Owner

Mugen87 commented Jul 25, 2024

Is there a way to see the code of this example?

https://github.com/Mugen87/yuka/blob/master/examples/navigation/navmeshPerformance/index.html

is there a parameter when creating the navmeshconvexregion to reduce the precision of it so I could have less region for better performance on my end?

NavMesh tries to merge convex regions when possible but this behavior is true by default. If you need a more simplified nav mesh, you have to ensure during the design phase of the underlying geometry.

@pierroo
Copy link
Author

pierroo commented Jul 25, 2024

thanks for all these!

so my (hopefully last) question would be:

can we use wanderBehavior AND followPathBehavior + onPathBehavior together?
I feel like they contradict each other.

I would like wanderBehavior because I want the vehicle to wander randomly without following a specific path.
Yet if I want the vehicle to respect the boundaries + respect the Y position, I need onPathBehavior and followPathBehavior which both needs a predefined path, which is contradictory to wander behavior, no?

There is also an issue that remains, when I give them a followPathBehavior, they completely disregard the navmesh in between: they can go through / fly above / go under the geometry etc; they just take the shortest LINE from point A to point B regardless of what's in between.

I tried to play with the value of followPathBehavior.nextWaypointDistance like in your example shared above;
I tried to add a onPathBehavior with a super low value for radius or a super high (onPathBehavior.radius), but to no avail: my vehicle will just cut through everything to reach their target and not respect the Y position of the regions.
Am I missing something?

EDIT: On the other hand, this example you shared seems to create a spatialIndex, yet it isn't used anywhere? (in the follow path function etc)
or is creating it enough for it to be used natively by every "findPath" function etc when the navMesh.spatialIndex is defined?

@hichemfantar
Copy link

I'm also trying to intergrate this with my threejs rapier based project.

@pierroo can you share anything that can help since you had a head start on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants