Alice Community

Alice Community (
-   How do I...? (
-   -   How to keep objects on screen? (

zwx650 02-16-2012 01:52 AM

How to keep objects on screen?

I am new to the forum. I tried to search for a similar thread, but couldn't find anything:

What should I do to find out if an object has moved to the edge of the screen and is about to be invisible, and then reposition the object to the center of the screen?

Thanks in advice for any helps!


Mr Kidnapper 02-16-2012 02:43 AM

You need some math for that. First you need to find out the field of view angle of the camera. I don't know this either, but a good estimate is just by sticking an object at the edge at a fair distance away, You then use the arctan2 function on this object. Your first parameter for the arctan function is the object distance to the left of the camera, and your second parameter is the object distance in front of the camera. What do you get? I don't know. At any rate, the result should be more or less the same as long as you keep the object more or less at the edge of the camera. Then you make a hardcoded (preset) number variable consisting of the result of the arctan function.
Congrats. you found the field of view angle.

Now you need to make sure that whenever your objects reach this edge (field of view angle), it teleports to the center of the screen.
For this, you make an if/else function. One thing you need to take note of is that you must also do the arctan thing on every object you intend on teleporting to the center of the screen. You should also save it as a number variable. So, if the arctan of the object is greater than positive FoV angle or greater than the negative FoV angle (The FoV, just with a negative sign), it does some method to move the object to the center.

This method is kind to you. You can do it simply by getting the distance to the left of the camera and having the object move that (negative) distance.

zwx650 02-16-2012 12:28 PM

Many thanks!
That's quite some computation involved :) Hopefully I will find time to give it a try and report back.

All times are GMT -5. The time now is 10:51 PM.

Copyright ©2021, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.