- Home /
Get offscreen gameobject nearest point of screen border
Hello, Im trying to reposition an offscreen GameObject (B) on its nearest screen border point (C). As you can see on this image. A is screen center point.
My first approach was to get the angle between A and the top center screen point (D on next image) in order to later calculate the angle between that and AB and finally get somehow C... But I cant even get started because Vector2.Angle returns the red angle shown on second image, and not a 90º as I would expected for AD...
Do you know a way to get the angles as I expected (and not from screen 0,0 point) or could you suggest me a different approach? Thanks.
Answer by hexagonius · Feb 08, 2018 at 09:41 PM
use camera.WorldToVieportPoint (or what the name was) on the object. Clamp01 x and y. reverse the transformation.
Your answer
Follow this Question
Related Questions
Vector2.Angles Direction 4 Answers
How to add force towards an object with variable degree accuracy 2d 1 Answer
How to find direction Vector for a collision surface? 1 Answer
Make an object come on the screen at random angles from random sides 0 Answers
How to change first person controller input when passing through a collider? 1 Answer