Tuesday, April 16, 2024
HomeSample Page

Sample Page Title


There are some apparent errors right here. Firstly:

Vector3 startPoint = cam.ScreenToWorldPoint(Input.mousePosition);

This doesn’t retailer your begin place in your member variable startPoint so you may learn it again on a later body. This creates a new non permanent variable known as startPoint that you just throw away on the finish of the operate – we are saying that this non permanent variable “shadows” the member variable, so any references their shared title will check with the non permanent as an alternative of the member variable as you supposed. Remove the Vector3 in entrance to make use of the member variable as an alternative.

Secondly, you do not present a depth worth to ScreenToWorldPoint. This can nonetheless work in case your digital camera is orthographic, however if you happen to’re utilizing a perspective digital camera then you definitely’re asking “What’s the place on this ray at a distance of 0 models from the digital camera?” – it doesn’t matter what display screen place you employ for that ray, the reply is all the time the digital camera’s personal place.

You could wish to assign Input.mousePosition to a Vector3 variable, and set its z coordinate to your chosen depth. Or hearth a ray utilizing ScreenPointToRay and verify the place that ray intersects your scene, utilizing the hit place as your begin/endPoint.

Thirdly, this solely measures distances alongside the world x axis. You can use Vector3.Distance() if you wish to measure the space on all axes. Or, if you wish to measure a pixel distance in your display screen, you may skip the ScreenToWorldPoint conversion solely, and work together with your Input.mousePosition Vector2s straight.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments