- Home /
How to constrain cursor to surface?
Hello, I am making a virtual tour using 360 images applied to spheres. I would like to create a cursor (like the one used in google maps) that is constrained to the surface of the sphere. How could I go about doing this? Thank you!
The easiest approach I can think of is to raycast your cursor position, and draw a separate cursor (for example with a particle system) where the raycast hits:
Transform constrainedCursor = ...; // this is the Transform of the virtual cursor
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) {
constrainedCursor.position = hit.point;
}
// else handle when you don't hit the sphere
Answer by Bunny83 · Aug 08, 2018 at 10:43 AM
I'm not totally sure what you mean, but i guess you mean google streetview and not really maps? Google street view requires a lot of extra metadata. This includes at which height the floor is and also the rough geometry of the surrounding buildings. This geometry can be calculated from several different images from different perspectives but the algorithms requires are quite complicated.
In short assuming you have the required metadata where the floor is you can either build a mesh collider with that data and use Collider.Raycast to determine a point on the surface, or if you only have a floor you can simply use an infinite mathematical Plane and Raycast against that.
If this is not what you're after you have to be much more specific on what information you actually have and what the result should look like.
Answer by czc5473 · Aug 08, 2018 at 12:43 PM
Hello, thanks for the response. Yes, I did mean google street view. I do not have a floor, only the sphere with a reversed shader so that the 360 image is viewed from the inside.
Here, I have white rings in the sphere that act as a hotspot to transition into a different sphere by clicking on it.
It works fine but I would like to make it neater and copy the way the cursor in street view works (an arrow, confined to the ground plane, changes direction depending which way you orient the scene.) I hope this is specific enough.
Thanks again for your help
Your answer
![](https://koobas.hobune.stream/wayback/20220612172428im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI cursor position off 1 Answer
how to stop mouse going out of the screen ? 9 Answers
How do I change the hardware cursor? 5 Answers
Waste of time with gui ... hover and behind 2 Answers
Setting the mouse position to specific coordinates 5 Answers