CANNON.Ray(...).intersectBody doesn't update direction itself
See original GitHub issuenew CANNON.Ray(vFrom, vTo).intersectBody(body)
method doesn’t work without using ray.updateDirection
method (which was private in cannon.js).
body.addEventListener("collide", ({ contact }) => {
if (!grounded) {
const vFrom = body.position;
const vTo = new CANNON.Vec3(0, -1, 0);
const ray = new CANNON.Ray(vFrom, vTo);
ray.updateDirection(); // <------ I shouldnt need to update the direction
// manually before using intersectBody
ray.intersectBody(contact.bi);
grounded = ray.result.hasHit;
}
});
A bug also encountered here but you should dig into the code.
Also, thanks for your port and fork !
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to use ray plane intersection & update point vector 3?
I want to use a ray like a line and update the end point vector 3 when a plane intersects the ray. Is...
Read more >Ray-bounded plane intersection - Stack Overflow
The ray has an origin and a direction. First I calculate the intersection point with an infinite plane with the formula. t =...
Read more >Ray-Box Intersection - Scratchapixel
Figure 3: a ray intersecting a 2D box. The ray doesn't necessarily intersect the box. In figure 3, we are showing a couple...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After doing more digging I will need to consider this further. Updating the intersect methods API as I suggested above would cause undesirable behavior when initializing the Ray with a RayOptions that contains a
result
prop - and I believe this pattern may be useful for memory sharing.The
Ray
intersect methods were not initially intended for manually raycasting against individual bodies, but they are suitable for it. Maybe be could develop another layer of abstraction for user-facing raycasts.Your destructuring isn’t correct:
should be