A rendering technique to create a 3D perspective in a 2D map
Questions tagged [raycasting]
1193 questions
-1
votes
1 answer
Why would ScreenPointToRay be pointing in the wrong direction?
I'm having trouble with getting a mouse event on a 3D object in Unity. MonoBehavior callbacks not responding, and ScreenPointToRay produces very strange results.
Using Unity 2021.3.12. I want to simply know when a 3d object is clicked. I tried using…

DaveA
- 11
- 5
-1
votes
1 answer
Unity2D raycast pointing at the wrong target
I am working on a script which makes a raycast going in the direction of the mouse. But for some reason it doesn't follow the mouse, it goes directly forward.
void Update()
{
if (Input.GetMouseButtonDown(0))
{
CastRay();
}
…

Zero
- 23
- 5
-1
votes
1 answer
How to calculate distance from a player to a dynamic collision point
I'm trying to create sensors for a car to keep track of the distances from the car to the borders of the track. My goal is to have 5 sensors (see image below) and use them to train a machine learning algorithm.
But I can't figure out a way to…

Pedro Renato Mello
- 88
- 1
- 8
-1
votes
1 answer
How can i fix this script in roblox studio?
if item:IsA("BasePart") then
item.Color = Color3.new(1,0,0)
I want to make a mouse raycast to place colors on parts and it shows me this error.
Error:attempt to index nil with IsA
I tried to change the script a bit and it ended…

Fried Fries
- 1
- 1
-1
votes
1 answer
Get the raycast direction from the position of the player and the throwing object
I want to know how I should rotate my Raycast start point (Raycast direction) when I want to get an object in front of the Object from the player's perspective.
This is how I like to use it.
startTransform.eulerAngles = ???;
if…

Fabian
- 71
- 2
- 10
-1
votes
1 answer
C# Unity Raycasting / BoxCast / SphereCast in a half sphere shape
The image above shows a boxcast, for what im trying to achieve this wont work.
Essentially what would be best is to cast a half sphere or a a quarter sphere like I drew on top of the boxcast screenshot.
Im trying to make a system for the cannons to…

Mad Hatter
- 85
- 9
-1
votes
1 answer
Raycast check crashing UE5
I am trying to check what a multi line trace by channel is hitting by printing every hit object's name to the log, however the engine keeps crashing due to (I assume) a memory error.
I've tried only printing the first object, which works, but since…

zyrg
- 3
- 1
-1
votes
1 answer
How to check that geographical coordinates (latitude, longitude) exists inside a polygon?
I want to check whether an address (long, lat) exists inside or outside of a polygon.
I have an address with latitude and longitude values. Address(,long =16269479, lat =58606014)
and polygon(lat, long) with its vertices POLYGON((16270489, 58824802)…

learner
- 37
- 7
-1
votes
1 answer
Ray Casting floor with HTML canvas
I am coding a small Javascript/ HTML-canvas Wolfenstein style game. I am following Permadi tutorial.
For now I did suceed to implement the textured wall raycasting. What I want to do now is to do the floor raycasting.
As far as I understand, when…

Toto Briac
- 908
- 9
- 29
-1
votes
1 answer
Raycast from the player position to the mouse position within range
I want to make a raycast from the player position to the mouse position but it should only have a certain range.
I have tried the following:
using UnityEngine;
public class Raycasting : MonoBehaviour
{
public GameManager gm;
Vector3…

Arbalistic_Cow
- 9
- 1
- 4
-1
votes
2 answers
How do you use a variable declared inside a function in another function? (C#) UnassignedReferenceException: The variable inRay has not ben assigned
So i'm playing around in Unity MLAgents, and wanted to add the position off objects that a Raycast hits to the agent's observations.
This has really been an adventure for me as i don't know anything about Unity or C#, and i know this sounds easy…

LSX Y
- 3
- 3
-1
votes
1 answer
Raycast problem, when you have many objects in the scene unity3d
i ve 15 objects in my scene, and when using raycast it takes the first objects near the camera, even if you clike the last objects it will destroy the first one.
here is my code
using System.Collections;
using System.Collections.Generic;
using…

jonathan pascal
- 95
- 4
-1
votes
1 answer
Unity Raycasting: "Camera.main.ScreenPointToRay" works, "new Ray(...)" does not
right now I'm working on a planet generation project in the Unity engine.
The problem I have happens when I want to place plants on the planet surface.
My approach is to cast rays from the center of the planet out towards the surface to get the…

BanditBloodwyn
- 53
- 8
-1
votes
1 answer
can i move a gameObject based on just its name?
Im using a raycast, putting its RaycastHit into a variable called raycastHit, using that to get the raycastHit.transform.name, could i then use the information from the name of the gameObject to move its position? Or if not, could i get the…

TerazikMubaloo
- 43
- 6
-1
votes
1 answer
im having a problem with an if statement that is looking at the layer that my raycast hit
im having a problem, which i think might be that im not looking for the layer that the raycast is hitting, correctly
if (raycastHit.transform.gameObject.layer == groundMask)
{
Debug.Log("heavy");
state =…

TerazikMubaloo
- 43
- 6