threejs-journey.com/lessons/raycaster-and-mouse-events
1 Users
0 Comments
42 Highlights
0 Notes
Tags
Top Highlights
test if an object is behind the mouse
shoot a ray through and see if those spheres intersect
Instantiate a Raycaster
change the position and direction where ray will be cast, we can use the set(...)
first parameter is the position and the second parameter is the direction
direction has to be normalized. A normalized vector has a length of 1. Don't worry, you don't have to do the mathematics by yourself, and you can call the normalize() method on the vector
normalize() method making sure that the vector is 1 unit long
cast a ray and get the objects that intersect
intersection is always an array
ray can go through the same object multiple times. Imagine a donut
returned array contains much useful information
test if there is a wall in front of the player, you can test the distance
change the object's color, you can update the object's material
show an explosion on the impact point, you can create this explosion at the point position
things while they are moving, we have to do the test on each frame
update our raycaster like we did before but in the tick function
now update the material of the object property for each item of the intersects
they all go blue but never go back red
turn all the spheres red and then turn the ones that intersect blue
need to cast a ray from the camera in the mouse's direction
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.