I am trying to make game like AirStrike3D where my Airplane along with camera will move in the Z direction…camera will also scroll along X axis a little bit say 500 meter or something ( so that i get more space for object to be placed ) and I have coded for the airplane like where I have given var horizontal extent beyond which airplane cant go …Camera is at 55 degree to the terrain and it scrolls left n right as per the distance between Camera and object (( camera.position - object.position) >scrolldistance) then move camera ). NOw I have given a horizontal extent for the Airplane so that it cannot go beyond certain limit but this gives problem when i move my airplane forward and go to left even though there is space left but my airplane cannot go beyond limit …If i increase this vertical extent then when i m at initial position i.e. near the camera it will go out of screen … I hope i have succeded it in explainig or visualising the problem I am facing
NOW is there any possibility that code can be written for plane say Plane can not go beyond camera’s FOV ?
i have a simple solution for you, take the position of the object tht you want to keep inside the frustum of the camera and change it from world point to screen point using this following function.
if it is negative on x or y it is out of the screen on left or bottom respectively. and if it is more than 1 on x or y, then it is out of the screen on right or top respectively.
Since you know when it goes out you can restrict it from moving when the value turns negative or more than one! Hope it is clear!
This lets you calculate the frustum (or at least frustum planes) of a camera. The frustum is the “pyramid” inside which objects are visible to the camera.
///JmD
Have you tried attaching colliders to your camera to limit movement? You can sort them into layers to make sure enemies can go beyond the screen limit but the player can't etc.
Have you tried attaching colliders to your camera to limit movement? You can sort them into layers to make sure enemies can go beyond the screen limit but the player can't etc.
– asafsitnerdid you try with changing it from world to viewport coordinates?
– flamy