# Raycasting A 2D Point in the World

**URL:** <https://forums.unrealengine.com/t/raycasting-a-2d-point-in-the-world/425199>\
**Category:** XR Development\
**Tags:** matrix, raycasting, unreal-engine, CPP, question\
**Created:** [May 17, 2018, 1:16pm UTC](https://forums.unrealengine.com/t/raycasting-a-2d-point-in-the-world/425199 "2018-05-17T13:16:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SysOverdrive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SysOverdrive](https://forums.unrealengine.com/u/SysOverdrive)\
**Post date:** [May 17, 2018, 1:16pm UTC](https://forums.unrealengine.com/t/raycasting-a-2d-point-in-the-world/425199/1 "2018-05-17T13:16:32Z")

</div>

Hi Guys,

so I am basically trying to make a plugin for Unreal Engine for the pupil labs HTC Vive device in VR. This device does eyetracking and has as inputs the following

Inputs:

2 floats representing the current position of the eye in the square (x,y)

(0, 0) representing the down left corner

(1, 1) representing the up right corner

I basically get data such as (0.5 , 0.5) which represent the center or (0.33, 0.65) some position in the field of view.

Output

The projection of the input in the world.

What I tryed to do

```
UPupilPlayerController->GetPlayerViewPoint(CameraLocation, CameraRotator);
const FVector StartTrace = CameraLocation;
	

const FVector ForwardVector = CameraRotator.Vector();  
    FVector	*PlanePoint = new FVector(x, y, 1);
FVector *EndPlanePointTrace = new FVector(); ///REAL ■■■■■■■■■■■■ 

*EndPlanePointTrace = ((ForwardVector *220.f) + *PlanePoint);

 (GetWorld()->LineTraceSingleByChannel(*HitResult, StartTrace, *EndPlanePointTrace, ECC_Visibility, *TraceParams)

```

Also there is the implementation for this already in Unity which looks something like [this](https://github.com/pupil-labs/hmd-eyes/blob/d35e7ed3c3bab9e3e9d31e36e610dff3097fe446/unity_pupil_plugin_vr/Assets/Market%20Scene%20Demo/Scripts/MarketWith2DCalibration.cs) line 64

I am basically trying to mimic sceneCamera.ViewportPointToRay (viewportPoint);

The current status of my project is free on [git](https://github.com/SysOverdrive/UPupilLabsVR).

---

<div class="post-metadata">

**Author:** ![Schnarek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schnarek](https://forums.unrealengine.com/u/Schnarek)\
**Post date:** [October 18, 2018, 7:32am UTC](https://forums.unrealengine.com/t/raycasting-a-2d-point-in-the-world/425199/2 "2018-10-18T07:32:00Z")

</div>

Hey Sys,

first thank you for your work.  
Did it work plausible for you and stable ?

Cheers  
Arthur

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [October 18, 2018, 7:45am UTC](https://forums.unrealengine.com/t/raycasting-a-2d-point-in-the-world/425199/3 "2018-10-18T07:45:07Z")

</div>

Try this

```
UPlayerController* PlayerController = ...
PlayerController->DeprojectScreenPositionToWorld(ScreenX, ScreenY, OutWorldLocation, OutWorldDirection);

```

More info on: \>[DeprojectScreenPositionToWorld](https://api.unrealengine.com/INT/API/Runtime/Engine/GameFramework/APlayerController/DeprojectScreenPositionToWorld/index.html)\<

OutWorldLocation and OutWorldDirection is your ray that you can shoot from the scene. You can check if it hits a plane with this API

```
FPlane PlaneToHit = FPlane(FVector(0, 0, 0), FVector(-1, 0, 0));
FVector WorldHitPosition = FMath::RayPlaneIntersection(OutWorldLocation, OutWorldDirection, PlaneToHit);

```
