Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Make your voice heard. Take the 2019 Developer Survey now

Questions tagged [raycasting]

A technique for using rays to determine points of intersection. Often used in lighting simulation.

0
votes
1answer
34 views

Can't figure out why my mouse picking code doesn't work

I am trying to create code to check for intersections between bounding spheres and the mouse. I get a mouse ray but it doesnt seem to point in the direction you think it should Attached is a ...
0
votes
0answers
10 views

rayTest for cutted by stencil objects

I have red rectangle based on which I am cutting (using opengl stencil) all of the green rectangles, like shown in the following screenshots a) before cut b) after cut When I run rayTest(bullet ...
1
vote
2answers
49 views

How can I check if the mouse hits a quad in 3d, and where it hits it?

I have a sketch that produces the following: ...
0
votes
0answers
23 views

The Raycasted plane (surface) ascend or descend with my camera

I would like to be able to draw an infinite plane in order to do multiple FX (such as a fog floor) later. I used the following shader that works except that the plane (surface) seems to follow my ...
0
votes
1answer
22 views

Raycast does not go to target position

There is a part in my script where I need to make a raycast check from my gun's muzzle to the enemy. This enemy could be anywhere around player. I found my ray is not connecting to the target ...
0
votes
1answer
20 views

Get closest point on box to line

Eventually this problem will be 3D. My player is looking forwards. There is an axis-aligned box on the screen (FOV is guaranteed to be 90, so boxes behind the player aren't considered.) I want to ...
1
vote
4answers
99 views

How can I convert Physics2D.Raycast to Physics2D.BoxCast to yield the same results?

This question has been updated to better reflect my current issue, and some of the progress made while solving it. I've been working on a 2D character controller that uses raycasting to detect ...
0
votes
1answer
64 views

How is raycasting implemented

I know what it's used for, I know what it does. What I am essentially asking is what is the math/code behind how it works? I'm aware that any custom implementation would likely be slower than an ...
0
votes
0answers
16 views

Why is it when I grab at a point it “jumps” upward?

So I've got a mechanic that lets me grab vertices. Something in my code (I think it's got to do with the clickRadius) keeps causing a grabbed vertex to "jump up". Example: https://i.imgur.com/0S6ZyRK....
-1
votes
0answers
25 views

Unity5 Boxcast/ Raycast Rotate with Parent

I started with the API Scripting reference's Physics.BoxCast example code: [https://docs.unity3d.com/ScriptReference/Physics.BoxCast.html] ...and it works great... until the game object rotates, see: ...
0
votes
0answers
39 views

Explanation Morgan's McGuire Screen Space Ray Tracing method

I tried to implement the Morgan's McGuire method, but my attempts failed. He described his method here: Screen Space Ray Tracing. Below is my code and screenshot. SSLR fragment shader: ...
-1
votes
0answers
185 views

Making a fully functional SteamVR UI Pointer in Unity?

I tried this tutorial and now can click buttons with a pointer, but that example ends short of anything truly useful as you cannot interact with scroll rects or anything beyond clicking. What I need ...
0
votes
1answer
52 views

How would I properly flip a character when they reach the edge of a ground object in Unity 2D?

The idea here is that the raycast shoots downwards from an empty game object and when it detects that there is no ground below it the character should bounce back and walk the other way. When I get to ...
0
votes
1answer
40 views

Unity: How many Raycasts per Sphere Collider?

I understand that a simple sphere collider in Unity is a raycast in all directions with a certain length. How many Raycast events does a sphere collider trigger? At what degree increments are the rays ...
1
vote
1answer
59 views

Noise when using SSLR (Screen Space Local Reflections)

When I tried to apply reflections to my scene, I ran into the problem of noise: My fragment shader code: ...
1
vote
1answer
64 views

Pathfinding to Get In Attack Range with “Transparent” Tiles

Currently I'm using A* and a raycasting algorithm to determine the path an entity (Player) should take to get close enough to the enemy (Enemy). The player has an attack range (it's illustrated around ...
0
votes
2answers
37 views

Bullet spread changes depending on the camera direction

I'm working on an FPS game. I want to make a little bit of difference in shooting direction, only on the horizontal axis. To do this, I wrote this code: ...
0
votes
1answer
192 views

Why is my spherecast returning an incorrect hit on mesh collider? (Unity)

I have a mesh collider that is largely a flat plane facing up. Any SphereCast against that surface should return a normal of Vector3(0, 1, 0), but that isn't always happening. When near an edge on the ...
0
votes
0answers
20 views

Only do 1 SphereCastAll in Unity3D? [duplicate]

I just want to make one SphereCastAll with a center and a radius. I don't want unnecessary sweeping in a desired direction with a desired length. How is this achievable? My solution is pretty ...
0
votes
0answers
8 views

Unity3D: Multiple OnTriggerEnters are called before the first one could finish and destroy the object

I'm working on a projectile which explodes when it reaches a destructible object and damages its voxels. (The projectile is a trigger) But the problem is that I use raycasting in ...
0
votes
1answer
61 views

Determine if ray hits an edge of a model in Unity 3D

How can i determine if a ray was hitting an edge of a mesh? The figure below shows what I want to achieve: Any ideas?
0
votes
1answer
192 views

How to raycast in MonoGame 2D?

Currently I am using a Ray class that I built myself. The following is for brevity. ...
0
votes
1answer
29 views

Spherecast - enabling MeshRenderer of selector target around prefabbed object once hit and disabling Meshrenderer when not hit anymore

I have an interesting problem - I have been looking up for solutions on this but I think there is something I am missing and I require a little more knowledge. I have a scene and the scene has an ...
1
vote
1answer
45 views

How to select two different instances in Unity C#

I have 2 Balls, 2 Nodes, and 1 Hand. I can pick up a ball, send it to a Node, grab it, put it on another Node, but I can't grab any other balls. The problem is that the Ball is defined publicly in ...
3
votes
1answer
29 views

Isolate UI elements from 3D scene

this might seem like a silly question but I'm raycasting on specific objects (Targets) in a scene and zooming in on them but i also have a few UI elements (buttons, toggles...) on the side of the ...
0
votes
1answer
108 views

Unity 2D Tap to shoot at mouse position on android device

Hello everyone i am really stuck at the moment and would appreciate any help if possible. I have my game where i move the player up and down with 2 buttons on the bottom left of screenshot. I also ...
0
votes
0answers
96 views

How can I raycast a floor in a simple raycasting engine?

I've been following the infamous lodev raycasting tutorial for a little while now but I can't make heads or tails of how the raycasting for the floor/ceiling works. He seems to be drawing the floor ...
0
votes
0answers
52 views

Raycasting — invalid floorcasting texture mapping

The problem is that the floor moves with the player in same time. In the correct implementation, the player must walk on the floor. I attach the animation on which this effect is visible (in spoiler), ...
0
votes
1answer
175 views

Why RaycastAll misses some objects?

Update 2 (see below) I'm writing a turn-based game. During setup phase time scale modifier equals to 0, what prevents running of any physics-based code and FixedUpdates. User have freezed action and ...
2
votes
0answers
224 views

ray-casting, floor-casting part fails

I'm currently working on a ray-casting engine in Java and I can't figure out what's wrong with my code. For the learning and theory I use: The permadi tutorial: ( https://permadi.com/1996/05/ray-...
1
vote
1answer
113 views

efficient 2D light source

I wanted to add a light source for a project I'm working on, and luckily I had some code based on this article: http://ncase.me/sight-and-light/, but when I ran the code after carefully transplanting ...
0
votes
0answers
29 views

Issue in projecting mesh onto the image

I have a triangle mesh which I read from ply file and build AABB tree using it. ...
1
vote
0answers
27 views

Best aproach to Ground level detection for spells/skills

I'm making a 3d Hero Defense/Tower defense kind of game with unity3d. A made a skill system with scriptable objects that lets the Defender use skills on the terrain doing damage to enemies that can be ...
0
votes
1answer
239 views

Difference between 'max distance' and 'radius' in Physics.SphereCastAll

I needed a way to check for all gameobjects within a set sphere of my player object. I found Physics.SphereCastAll which will return a RaycastHit[], exactly what I wanted. But, I am having trouble ...
0
votes
1answer
146 views

Debug.DrawLine doesn't go straight

Heres the code: ...
0
votes
1answer
47 views

RayCast seems to ignore some objects?

I'm currently using a Raycast both for my movement check aswell as a focus-setting check, both checks use pretty much the same code. The problem i'm having is that the Raycast goes through some ...
0
votes
0answers
26 views

[Unity]: Make one button highlight color activated when pointing at another button in same location

I have two buttons. One is a play button. Another is used as a tint for a background so when I am pointing at play button, the background should change its tint. Problem is when I point at play ...
0
votes
0answers
19 views

Raycasting issues

I have this raycasting code: ...
0
votes
0answers
61 views

Unity C# How to calculate end position between two vector3's using max distance

I know the title is a bit confusing. Reason why I haven't been able to do this myself is because I am a bit confused on how to go about doing this. This is what I want: When the player uses a skill,...
0
votes
1answer
42 views

Enemy fire does not travel to player using RayCast2D

Enemies are using raycast to fire and detect player. The bullet has its own script that makes it move forward after instantiating it, but the problem is that it always moves in the right direction and ...
0
votes
2answers
203 views

How can I correct an unwanted fisheye effect when drawing a scene with raycasting?

Hello I have a game using raycasting for the TI Nspire in Lua, and when the player faces a wall so that their degree they are facing is perpendicular to the length of the wall, I am having what is ...
0
votes
1answer
234 views

Using raycast to detect whether a wall immediately blocks a player in Unity C#

I am working on a game project of which involves a procedurally generated maze. Within this maze, there are different types of tiles, such as walls and gates. I want to program the player so that it ...
1
vote
2answers
142 views

In Unity, is there a difference between Vector3.down and -Vector3.up?

I've noticed numerous tutorials and examples using something like "transform.up * -1" or "-Vector3.up" instead of simply saying "transform.down" and "Vector3.down". Is there a good reason for this, ...
0
votes
2answers
263 views

Raycast in Unity for ground detection returns false while touching ground

I'm using a raycast to detect the player's distance to the ground for a hovercraft game. The raycast works correctly (returns true and also returns the distance to the first impact) until the moment ...
1
vote
1answer
74 views

Unity 2017.3.of3 Raycast2D randomly misses objects

2d up down platformer. Character has 2 Rays(one left one right) going down, when either Ray's hit distance hits between -1 and 1 it should call a function which will change character direction from ...
4
votes
0answers
111 views

Determine user mouse selection of 3D Object for multiple viewports

I am currently working on setting up some world objects for my level editor and am running into a bit of a snag. When I get the hit location from the mouse raycast, I would like to determine what part ...
2
votes
1answer
84 views

Drawing Explosions Respecting Walls

I am creating a tiled game (2D top down) and I created explosions working this way: The blue lines are walls, the white grid is accessable space. The red dot is the origin of the explosion with the ...
2
votes
1answer
73 views

How can I ungrab the grabbed Object in Unity?

I modified a grab Script to my purpose, I can grab the Object and make it a parent to the character with the Key "G" but I want to let it go and detach the parent of the picked Object with "H" with ...
0
votes
0answers
61 views

Cast a Ray In C++ Directx9.0c

I'm in the process of attempting to mod Quake 4, and one of the features I am attempting to implement is teleportation. With that said, I want to know how to perform the casting of a ray. I wish to ...
1
vote
1answer
59 views

How to prevent cube intersecting with other objects when moved around with mouse?

I want to allow the player to freely place cubes anywhere they like in 3D space, but the cube being moved around is not allowed to intersect with other objects. Currently I do a ray cast based on ...