question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CANNON.Ray(...).intersectBody doesn't update direction itself

See original GitHub issue

new 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:open
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
codynovacommented, Apr 6, 2020

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.

1reaction
codynovacommented, Apr 6, 2020

This does not work:

Your destructuring isn’t correct:

body.addEventListener("collide", ({ contact: bi }) => {

should be

body.addEventListener("collide", ({ contact: { bi } }) => {
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found