raycasting

Three.js Raycasting with Camera as Origin

亡梦爱人 提交于 2021-02-10 07:55:41
问题 I'm trying to determine whether a point in space is visible to the camera or hidden behind other objects in the scene. I'm doing this by casting a ray from the position of the camera to that point in space and testing if that ray is intersected by an set of intersectable objects. My problem is no intersections occur until the camera position itself intersects one of the objects in the set of intersectable objects. I've created a jsfiddle in which, if an intersection is detected, a line is

Raycaster displays phantom perpendicular wall faces

有些话、适合烂在心里 提交于 2021-02-08 06:58:19
问题 The output looks like this: You should just see a flat, continuous red wall on one side, blue wall on another, green on another, yellow on another (see the definition of the map, testMapTiles , it's just a map with four walls). Yet there are these phantom wall faces of varying height, which are perpendicular to the real walls. Why? Note that the white "gaps" aren't actually gaps: it's trying to draw a wall of height Infinity (distance 0). If you specifically account for it (this version of

Make an object collide with certain other objects when moved to RaycastHit point in Unity3D?

人走茶凉 提交于 2021-01-29 19:33:59
问题 I'm making a simple building system using Raycasting from the mouse pointer. The object that is to be placed is moved (and cloned on click) to the RaycastHit.point of the ray, but I want it to fully collide with objects of its own type, shifting its position relative to the hit point. The object can intersect the terrain as shown in the gif, but should not be inside of the already placed wall blocks. I tried using hit.distance but couldn't figure the detection out, since the object is being

How to create 3D tile maps using a Plane object divided into tiles?

大城市里の小女人 提交于 2021-01-28 17:53:15
问题 I want to create a 2D plane centered on 0,0,0 in 3D world space. Then, I want to define this plane in 2d tile coordinates. So e.g. a plane divided by 3 tiles would become a map of an array [3,3] The issue is that this would still give a tilemap with negative points. The world upper left -1,1 would be 0,0 in the array -1,- would be 1,0 and so on... World: -1,1 0,1 1,1 -1,0 0,0 1,0 -1,-1 0,-1 1,-1 Array: 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 My main hope with Unity was that I could avoid the math

How to check ground for unity2d platformer game

微笑、不失礼 提交于 2020-12-15 04:59:05
问题 I am trying to make a 2d plat-former where you see the player from the side. I want him to be continuously moving and you have to press space at the right time so he doesn't fall. Right now everything works but he doesn't collide with the ground. I want it to be like he's running behind a wall so I want to ignore a certain layer I have made and collide with the boxes below that. So far I have tried ray casting, watched multiple tutorials, and did box collisions. Box collisions worked but to

Ray-square intersection 3D

[亡魂溺海] 提交于 2020-08-25 06:51:33
问题 I know how to compute a ray-plane intersection, but how can I test if the intersection point is within a square on that plane? I was testing if the point was within a distance from the center of the square but I'm not sure if this is correct. 回答1: Here is a method that works for any convex polygon: (see simplified version for squares at the end of answer) Let p1,p2,p3,p4 denote the four vertices of your square and let q denote the intersection between the ray and the supporting plane. Let n

Change color of mesh using mouseover in three js

北战南征 提交于 2020-08-24 06:20:00
问题 I've put together a WebGL script that displays several meshes using jsonloader and three.js and I now want to add MouseOver and onClick events. The first of these is simply changing the colour of the mesh when the mouse hovers over it: function render() { requestAnimationFrame(render); mesh.rotation.z += 0.090; raycaster.setFromCamera(mouse, camera); var intersects = raycaster.intersectObjects(scene.children); for (var i = 0; i < intersects.length; i++) { intersects[i].object.material.color

Raycast in Three.js with only a projection matrix

依然范特西╮ 提交于 2020-06-24 11:36:12
问题 I'm rendering some custom layers using Three.js in a Mapbox GL JS page following this example. I'd like to add raycasting to determine which object a user has clicked on. The issue is that I only get a projection matrix from Mapbox, which I use to render the scene: class CustomLayer { type = 'custom'; renderingMode = '3d'; onAdd(map, gl) { this.map = map; this.camera = new THREE.Camera(); this.renderer = new THREE.WebGLRenderer({ canvas: map.getCanvas(), context: gl, antialias: true, }); this