Game Development Community

World limit... Non-square limits possible?

by amaranthia · in Torque Game Builder · 09/11/2006 (8:25 pm) · 11 replies

I'm trying to figure out the best way to handle a world limit that isn't square. This my problem: I have some chickens flapping around the screen, and they need to roam around in an area that is not square (looks more like an octagon). I suppose I could drag a bunch of scene objects and place them around the edges, but this seems pretty messy. Is there an easier way to deal with non-square world limits?

#1
09/11/2006 (10:50 pm)
How about creating a custom collision polygon? That seems like the best way to me, but, I have been fooled before...
#2
09/12/2006 (12:03 pm)
I would just do this in script, instead of using the built in world limits (which must be square unless you modify the code to do a radius check).

Every movement update, see if their distance to the center of the screen (or camera, or however it makes sense in your game description) exceeds the radius of the circle you want, and have them change direction if it does.

FYI, the world collision check is not related to the custom collision polygon concept--in other words, you can't create a custom collision polygon for the world limits themselves--it's simply a box.
#3
09/12/2006 (1:41 pm)
This is where a onNotCollidingWith callback would be useful. You could set a sceneobject sized appropriately and set a suitable collision poly. When your chicken is no longer colliding with that object, it's moved too far away.

Although given that most objects will likely spend most of their time not colliding with other objects, it'd probably have to be carefully implemented to prevent massive amounts of CPU time being devoted to non-collisio checks.
#4
09/12/2006 (5:51 pm)
Hey Stephen, can you point me to the methods I should look at to custom script this?

(@Joe & Philip, I'm going to try the custom stuff first to keep performace high. hopefully it will work!)
#5
09/12/2006 (8:00 pm)
Depending on how many chickens you have it could be a performance hog, but in general during your ::onUpdateScene() callback you could iterate over your chickens and make sure they are within limits, and if not, send them in a random direction somewhere towards the screen center.

I think that's the callback that's available..can someone correct me if I'm wrong? Don't have source with me at the moment.
#6
09/12/2006 (9:17 pm)
There are going to be loooots of chickens! I'll give it a try and see what my performance looks like.
#7
09/12/2006 (9:25 pm)
Well, are we talkin dozens, hundreds, or thousands? Dozens, and possibly even hundreds if you optimize your distance check algorithm (hint, squaring a number is MUCH faster than taking the square root of a number) shouldn't be too much of an issue.

PS: The game sounds pretty interesting :) I'm picturing all these chickens running around with their heads cut off, and you have to glue the heads back on right now...not sure if that's what you have planned, but might be interesting, hehehe.
#8
11/17/2006 (8:19 pm)
Any luck with this amaranthia?

A work around would be to set the World Limit to cover the top,bottom and sides of your octagon.. then you would just need 4 scene objects for others...
#9
11/17/2006 (10:35 pm)
Similar to the Not-Colliding-With idea, you could have the chickens do a pickPoint with a very narrow mask for an object below them (the fenced area or something) and if they've left it, pull them towards the center or make them reverse direction or something.
#10
11/19/2006 (11:32 pm)
Just a thought. Would a trigger object work in this situation? Using the onExit trigger (or whatever its called) callback? Can you even set spherical collision on triggers?
#11
12/14/2006 (9:19 am)
That would probably work. In the end, I decided to use a tilemap to solve the problem. So far, so good!