Need Mouse.hit type info, but from TouchDevice, but from center screen cursor (not from where they touch)…
So what I mean:
I have some code from this forum that’s causes the character to look (turn his head) at the spot the mouse is hitting.
But when I test it in tablet, the character looks at the spot that my hand touches.
When on a touch device, I want the character to look at the point that is center screen (where the “+” cursor is hitting).
Any help on that? (kind thanks!)
You can just use Camera:ScreenPointToRay()
and then raycast
1 Like
Well, I “hearted” this, then I realized I don’t know how to do it. I looked up “Camera:ScreenPointToRay” and still didn’t know how to do it. How do I add a raycast to a ScreenPointToRay ?
Thanks for any links or help you send.
ScreenPointToRay(x, y)
shoots a ray from point (x, y) on the screen in the direction that the camera is facing, you can get the center of the screen using Camera.ViewportSize.X
and .Y
then dividing those values by 2
You can then use workspace:Raycast(origin, vector, params)
to raycast towards where the camera is facing. The origin
is where the raycast starts from, you can probably just use Ray.Origin
from the ray you got earlier or use the position of the HRP. The vector
is the direction and length of the raycast, you can just do Ray.Direction * LENGTH
. Finally there is the raycast params, it is optional and is used when you want to ignore certain parts or terrain, and probably won’t be needed here
1 Like