berrur Posted July 29, 2016 Share Posted July 29, 2016 Hello guys, i'm totally new to Babylon and I was wondering if there's a way to check if an object is hitting the border of the screen and prevent it to get off the screen. This is what i wrote so far: http://www.babylonjs-playground.com/#SKWZP#0 I found these values manually, i hate to hard-code stuff inside my code but it was just for testing. if (box1.position.x > 6 ) { box1.position.x = 6; } if (box1.position.y > 4 ) { box1.position.y = 4; } if (box1.position.x < -6) { box1.position.x = -6; } if (box1.position.y < -4) { box1.position.y = -4; } Can you please me help to understand how can i retrieve the screen boundaries wrt the viewport? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 29, 2016 Share Posted July 29, 2016 Hey you should use Vector3.Project (http://doc.babylonjs.com/classes/2.3/Vector3#static-project-vector-world-transform-viewport-rarr-vector3-classes-2-3-vector3-) to project the box position to 2d and then check against the current resolution Other option: check if your mesh is in the active meshes by testing scene.isActiveMesh(mesh). If false then object is offscreen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.