question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ray casting not working

See original GitHub issue
var 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:closed
  • Created 12 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
WestLangleycommented, Feb 15, 2012

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

0reactions
lukebittscommented, Feb 15, 2012

Thanks everyone 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found