Convert GUI to LookVector

I’m currently in the process of making a custom joystick for mobile users.

I’m trying to covert joystick position to where the player looks.
I’m not sure how I should tackle this problem but I’ve run across the :Dot function and thought that might be how I accomplish it I’m just not sure how to implement it.

Joy stick (Please excuse the for some reason horrible video quality, please tell me if I should re-record it):

Thank you so much if you could help! <3
Also, tell me if I need to further elaborate!

I don’t think the dot product will help you here. I’m not completely sure about the kind of thing you want. If I understand correctly, you could just use right/left/up/foward etc. unit vectors and make a kind of tweening system where you incrementally move the camera towards that unit vector based on the direction they moved the joystick.

I “think” dot product will help him later as it compares the difference between two unit vectors but I guess it isn’t helpful now from what he stated.

Are you trying to make it so that the player looks in the direction the joystick is at? If so, .Unit would help.

Doing:
(centerPos - joystickPos).Unit will get the direction to look at, and from there you just need to set the character’s look direction. If the joystick position is at the center, you’ll get an infinite vector, so throw in a check to make sure that at least one component of the vector difference isn’t zero.

2 Likes

I’m having a bit of trouble converting the .Unit into a CFrame/Vector3 for the character to point at. Any ideas of how I could achieve it?

The X and Y axis on the joystick vector should equal either the X or Z axis on the player, in global coordinates.

Depending on how your camera is oriented, you may have to guess what each number means. For example:

local characterDirection = Vector3.new(joystickVector.X, 0, joystickVector.Y)

2 Likes

I could not get .Unit from Udim2 though.