Stack Exchange Network

Stack Exchange network consists of 175 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

Questions tagged [raycasting]

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

1
vote
1answer
36 views

What are some gameplay cases where knowing the Z as a result of the raycasting is useful in a 2D setting?

The context is an 3D engine with a 2.5D level format. Like a roller coaster tycoon level, with some other level features added, and layers removed. For example the tile functions have the following ...
0
votes
1answer
14 views

Unity AudioSource.PlayClipAtPoint - controlling attenuation

New developer here, looking to do some raycasting and controlling audio positioning in 3D space based on the raycasts interactions with other objects. I've got the raycast 'casting' and able to report ...
1
vote
1answer
44 views

Rigidbody & Ray alternative or optimization

I am creating an AI that moves around to certain points, but should interact with ais or objects seen. The ai should find other ai to comunicate or look for objects on the ground. It works with all ...
0
votes
1answer
32 views

In 2D, how can I improve character rotation using raycasts when dealing with sharp/convex edges?

Edit: After making some edits to my polygon collider (based on @Alex F's suggestion), I can indeed confirm that sharp, convex corners are causing the buggy ...
1
vote
1answer
21 views

Unity SphereCast HitInfo Give me an interpolation of the normal surface?

I'm doing a SphereCast for a GroundCheck of a player. I have my Raycast hitInfo, and here in the picture at the left, I Debug.drawRay in black the direction of the hitInfo.normal every frame It seems ...
0
votes
0answers
42 views

How to implement Microwave Signals in Unity?

I need to implement microwave signals for object detection in Unity. I know there are raycast sensors in Unity, but can microwave signals be simulated or can a proxy of microwave signals be created ...
3
votes
1answer
77 views

Why does my collider rotate correctly on a slope only when a ray is cast directly from its center?

Edit: This answer might also be helpful to those who come across this question. I've been messing around with raycast collisions and slopes, but am having an issue when trying to get my collider to ...
0
votes
0answers
24 views

Check gap in 3d environnement

I am in a 3d environnement, when I jump, i'm calculating the hitPoint of the end jump. I want to know when I jump, if there is a GAP between my initial point, and the end point. But I don't want to ...
2
votes
1answer
77 views

How to detect when the mouse is over a particular enemy collider, without falsely selecting bullet colliders?

I have an enemy shooting around. My game mechanic involves hovering over the enemy with the mouse to drain its health. While the enemy is moving, you need to follow it with your mouse. If you don't ...
0
votes
1answer
40 views

Raycaster calculation question

I am following this tutorial https://lodev.org/cgtutor/raycasting.html When deriving deltaDistX geometrically you get, with Pythagoras, the formula "sqrt(1 + (rayDirY * rayDirY) / (rayDirX * ...
0
votes
2answers
53 views

Difference between reflection mapping and raytracing

Both methods involve casting a ray unto the reflecting object. It will be reflected. In reflection mapping - the intersection of this reflected ray with the environment map (texture) will yield the ...
0
votes
1answer
57 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
11 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
54 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
24 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
31 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
28 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
149 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
70 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
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
46 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
96 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
73 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
43 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
284 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
22 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
91 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
277 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
35 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
50 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
37 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
125 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
58 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
211 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
279 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
127 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 ...
1
vote
0answers
30 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
359 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
186 views

Debug.DrawLine doesn't go straight

Heres the code: ...
0
votes
1answer
48 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
34 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
21 views

Raycasting issues

I have this raycasting code: ...
0
votes
0answers
65 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
45 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
220 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
289 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
161 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
369 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
75 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 ...