[SOLVED] Raycast troubleshooting

what is wrong in my code?

var camera = this.camera;
if (rh===0) {
    this.rayStart.copy(camera.getPosition());
    camera.camera.screenToWorld(e.x, e.y, 1, this.rayEnd);
    this.rayEnd.sub(this.rayStart).normalize().scale(RAY_LENGTH).add(this.rayStart);
    this.app.systems.rigidbody.raycastFirst(this.rayStart, this.rayEnd, this.onRayHit.bind(this));
}

I don’t see anything obviously wrong. It might be worth me pointing out that raycastFirst no longer takes a callback as the third parameter. See the API reference manual on that. That way is deprecated. Now you do something like:

var camera = this.camera;
if (rh===0) {
    this.rayStart.copy(camera.getPosition());
    camera.camera.screenToWorld(e.x, e.y, 1, this.rayEnd);
    this.rayEnd.sub(this.rayStart).normalize().scale(RAY_LENGTH).add(this.rayStart);
    var result = this.app.systems.rigidbody.raycastFirst(this.rayStart, this.rayEnd);
    if (result) {
        // Do something...
    }
}

But your should should still work. What isn’t working exactly?

Hi @will, i already tried doing that too, since i guessed that was the case, but i still get the error, when i click it say to check the console and when i check it i have
error-raycast
the line is the one with the raycastfirst

Well, I took a look at line 31648 of playcanvas-stable.dbg.js:

    ammoRayStart.setValue(start.x, start.y, start.z);

So according to the error, ammoRayStart is undefined. This means that the ammo.js library is not loaded.

Did you import the ammo.js WASM module into your project yet?

I did, but since i got an error i removed it, now added it again and have this error
error%20ammo

So that solved your original problem. This is a different problem. It’s now failing when creating a mesh collision shape. Are you able to debug that error? Personally, I would break into the debugger when that error occurs and determine which entity is the cause. Do you know how to do that?

uhm, if the problem is terrain.js the code that create the terrain i can set breakpoints to see when the error pop up, i can cut into segments of 10-20 lines at the start to reduce the range, is boring but useful. Have some better way to solve that to suggest?

When you do this, does the game work?

No @yaustar it break seems when it load the thieves house. not sure just started checking.

it seems it break here

Don’t get why without ammo it works and with ammo it brokes

Nope the problem is not the house, still looking for it

Not able to identify the problem here is the error

Just solved this error, changing the subdiision, but the raycast still doesn’t work :frowning:

The if (result) doesn’t fire the this.onRayHit function

Can you create a new small project that you can show this error with please? That will help us be able to look at what is causing the issue and potentially find a fix.

doing it, is there no way to duplicate scripts?

Copy/Download and Paste/Upload unfortunately at the moment.

did it, but to rebuild a ‘simple’ test is not easy since every script is tied to another, can’t you just test line 2544 why don’t fire line 2545 in player.js here? https://playcanvas.com/editor/scene/898756
if not i will keep adding scripts to the test scene untill it works.

We could but it’s a lot of code to debug as we don’t know what code is causing the issue exactly and there are other issues in that project making it difficult to isolate. If you can create the smallest example of what is causing the issue, the quicker and easier it is for someone to look at it.

What are the reproduction steps for making the bug happen?