I am trying to limit an object’s movement to the screen via something like this:
if (keepOnScreen) {
if (mouseLocation.x < screen.x ) {
mouseLocation.x = screen.x ;
}
else if (mouseLocation.x > screen.width) {
mouseLocation.x = screen.width;
}
if (mouseLocation.y < screen.y) {
mouseLocation.y = screen.y;
}
else if (mouseLocation.y > screen.height) {
mouseLocation.y = screen.height;
}
transform.position = mouseLocation;
}
This works, but of course the transform.position is the center of the object. I’d like to offset it by collision bounds. I can’t set up an invisible wall, because I’m forcing the object position via the mouse and I really don’t want to make the object move towards the mouse pointer using physics.