Z position is too far away when i do raycast

Hi @HasnainX,

Normally that shouldn’t be a problem.

Are you getting an error? Or simple doesn’t work?

Try sharing more info about your setup and code, and even better a sample project that reproduces your issue.

It seems there is an error coming up when running your project:

Have you looked at it?

this.aabbShape should be a Bounding Box for that method to work.


I do here in load-glb-container-external.js

It seems the error is coming from another script, raycast.js:

Specifically at line 23 you set this.aabbShape = bbox;.

But isn’t bbox undefined there? If you define it in a different script then you need to make sure to communicate that to the other script.

Check this manual page on some tips on how to handle communication between scripts:

https://developer.playcanvas.com/en/user-manual/scripting/communication/

I make the global variable bbox in load-glb-container-external.js so i can access anywhere in scripts by using this but show me error again i don’t know why.

Right, but the moment your raycast.js script assigns this.aabbShape to that global var it’s empty, so it doesn’t work. Here is me checking it with the browser dev tools:

If you’d like to keep using the global var then change line 40 on your script to this, and it will work:

var result = bbox.intersectsRay(this.ray, this.hitPosition); 

thank you so much :slight_smile:

1 Like

Green ball are placing in near space of model.I want to place the green ball on model what can I do
Your helping would be highly appreciated