Ray casting not working
See original GitHub issuevar geometry = new THREE.CubeGeometry( 30, 30, 30 );
var object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial({color:0x0000ff}) );
object.position.x = 0;
object.position.y = 200;
object.position.z = 0;
ray = new THREE.Ray(new THREE.Vector3(-500,210,0),new THREE.Vector3(500,210,0));
var c = ray.intersectObject( object );
am I forgetting something here? Because c is always empty but I don’t see anything being done differently in the ray examples.
Issue Analytics
- State:
- Created 12 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why is this Raycast not working
First of all, Physics.Raycast returns a bool, so you might want to poll it directly (" if(Physics.Raycast(transform.position, Vector3.left, out ...
Read more >Unity Physics.Raycast does not detect an object when it ...
A Raycast has a few parameters. I will explain each as there could be a few reason as to why it is not...
Read more >Ray casting not working! - Scripting Support
Hi, i want to achieve that i itterate over all terrain triangles and randomly spawn som vegitation on top of it like grass...
Read more >Raycast not working correctly : r/Unity3D
Raycast not working correctly. I'm working on a project trying to learn about raycasts and nav mesh agents. I have these bean agents...
Read more >Scripting API: Physics.Raycast
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You need to call
object.updateMatrixWorld()orrender()prior to your call toray.intersectObjects(). Also, as @alteredq pointed out, the second argument in the Ray constructor must be a direction vector – of unit length.Thanks everyone 😃