So i am at the Collisions Chapter and my Character can still run into the “notAllowed” Area.So pls Help me bc. my Ground is appearing but my Character can still run to the Trees.
My Url:
https://is.gd/TvuwvZ
You are sooooo close. There are 3 small typos in the code that are causing the problem here. The first you can see in the JavaScript console:
Uncaught TypeError: THREE.RayCaster is not a constructor
at isColliding (code.html:59)
at HTMLDocument.sendKeyDown (code.html:90)
If you look at line 59, you’ll find:
var raycaster = new THREE.RayCaster(marker.position, vector);
To fix problem #1, you only need to change RayCaster
to Raycaster
(lowercase c
):
var raycaster = new THREE.Raycaster(marker.position, vector);
Problems #2 and #3 are both 3 lines down:
if (intersects.lenght < 0) return true;
I’m pretty sure you can figure out both problems just by comparing the code to what’s in the book. It wasn’t simple to track these problems down after fixing #1. I eventually just started looking through the code line-by-line, though I started in isCollision()
since I new that collisions weren’t working. Luckily, it didn’t take too much time since isCollision()
is kinda small.
Hope that helps. If you run into any more problems, let me know!
-Chris