0

As I understood the only method to compute collisions with three.js is intersectObjects with a ray ...

I created an object that includes the basic elements of the collision : ground, walls, objects, stairs. with the firstpersoncontrols. I went with the idea that I should calculate the steering vector based on the direction in which the camera is currently traveling but it does not really work and I do not see where the error is.

I expected that the camera can not pass through ground, walls and objects with which she finds herself in a collision.

You can see the code here

WestLangley
  • 102,557
  • 10
  • 276
  • 276
Laurane Bernard
  • 209
  • 1
  • 2
  • 10
  • 3
    what is the question? what exactly did you expect vs. what is happening? – tucuxi Jan 12 '13 at 22:53
  • I expected that the camera can not pass through ground, walls and objects with which she finds herself in a collision. the staircase is to see if we can raise the camera ... I'm trying to understand how exactly the collision three.js and what we can and can not do. I read a lot of examples two objects collide, but I find nothing in the cases proposed ... – Laurane Bernard Jan 12 '13 at 23:16
  • @PeterMortensen three.js is not capitalized! – WestLangley Jan 08 '22 at 23:09

1 Answers1

2

three.js has no automatic collision detection.

You implement ray-casting with Raycaster now, not Ray:

Raycaster.intersectObjects( objects, recursive );

You also have to control the elevation of the camera yourself.

three.js r.54

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • ok i changed but I think that my method is not good because this doesn't work – Laurane Bernard Jan 12 '13 at 23:57
  • 1
    Your routine `detectCollision()` is not being called. Also, we can answer specific questions here, but we cannot debug your code for you. – WestLangley Jan 13 '13 at 02:08
  • Here I proposed to see if raycaster could apply to an environment to determine the collision mesh in an example that often comes as a question but did not find any answer yet after what I read .. . I am novice and still errors beasts. if nobody explains how the functions three.js walk learns how to use it. it's been three days since I tried the codes that I find to understand .... – Laurane Bernard Jan 13 '13 at 09:01
  • I changed the principe : I used a camMesh as camera avatar and a cube as wallMesh. I want attach the camera as camMesh. the camMesh is placed in wallMesh. the principe is to calculate the ray which start of camMesh and stop mouve when it is in collision with wallMesh. this method is better or not ? – Laurane Bernard Jan 14 '13 at 11:57
  • If I understand, what you propose sounds OK. Also study "collision maps" or "collision masks". You probably should "accept" this answer and post a new question so more people can help you. – WestLangley Jan 14 '13 at 15:12
  • in reality, I search a solution collision any physics motor for only firstpersoncontrols to integrate in controls.js. and in html you said if the mesh are solid (collision true) or not. through my readings three.js, the method seems to be that of a raycaster Vestor 4: purpose is it really possible? I do not know this method of collision map view of this after I read it seems rather adapt to a world 2d, right? if you have any interesting links on the collision map, I am interested ... – Laurane Bernard Jan 15 '13 at 07:25
  • I can only address three.js issues. Please make another post if you have other questions. Good luck!. – WestLangley Jan 16 '13 at 01:19