My crosshair is made with a couple of different vectors that is placed in a screen space camera canvas. I have tried to clamp it with different values to clamp to, none have worked. Anyone know how I can clamp it? And also does clamping something effect rigidbody velocity?
I like to handle this by anchoring a GameObject in the UI at LowerLeft, and then one at UpperRight. Then my script just has public Transform references to each of those and I use their positions. Code (csharp): float croppedX = Mathf.Clamp( mouseX, LowerLeft.position.x, UpperRight.position.x); // ditto above for Y... // and now use croppedX/croppedY to position your crosshair. Super-simple, plus the cropping instantly changes if the screen changes shape. You can also inset them slightly so that the entire + of the crosshair is onscreen, if you prefer.