- Home /
Collide edge of object with the edge of the screen
Hello! I'm trying to make an object collide with the edge of the screen, but so the actual collider is what causes the collision, and not the center of the object. Currently I'm using WorldToViewportPoint to calculate if the object is at an edge by using transform.position and checking whether it is larger than 1 or smaller than 0, which works perfectly. However the collision happens when the center of the object hits the edge.
I really want the edge of the object to cause the collision. I've been looking around and can't figure out exactly how to do this, I think it's something to do with collider.bounds? but I'm unsure.
Thanks! :)
This is what I have at the minute:
currentScreenPos = Camera.main.WorldToViewportPoint(transform.position);
if ( (currentScreenPos.x >= 1) || (currentScreenPos.x <= 0) )
{
// object's center point is too far left or right
}
Your answer
Follow this Question
Related Questions
how to scale an object in order to fix the screen dimensions 3 Answers
Stoping camera when character is falling. 1 Answer
how to have an object positioned relative to the screen(like a button) 1 Answer
Object isnt where its supposed to be when selected 0 Answers
How to render object in front of other object no matter position? 1 Answer