GhostControl issues

So most likely I am simply being ignorant, but here goes.

I’m attempting to use a GhostControl as a trigger, so that when a projectile hits the sphere, said projectile disappears.

I tried this in a otherwise blank SceneGraph, and it worked fine. But then I figured that in an actual game setting, other objects

would be overlapping the trigger as well, which could cause the projectile to disappear prematurely. So I set a for loop to activate if

there was anything overlapping the trigger, and check to see if the projectile was one of these objects. Unfortunately, although the for()

loop only runs if getOverlappingCount() is greater than zero, the getOverlapping(index) method inside the loop is causing a IndexOutOfBoundsException, telling me that there is nothing in index 0 of the trigger. Sorry if this is a stupid question but what am I doing Wrong?

post the code. Its hard to give an answer without seeing it first hand, we can only make assumptions otherwise

Of course.

int y = 0;

for (int x = target.getOverlappingCount(); x > 0; x–){

if( target.getOverlapping(y) == ball_phy) {






The int y is meant to cycle thru the overlapping objects, ball_phy is my projectile.

It seems to me that if nothing is overlapping, the for loop should not execute, but

it does, and then tells me that there is an exception from the getOverlapping() method

because there is nothing overlapping.

You go backwards in your loop and you start with the count as index…

I don’t think hes using the count as the index, he has a separate variable y, which he uses, but it is unnecessary. It would look a lot more cleaner if you did something like this:


for(int x = 0; x < target.getOverlappingCount(); x++) {

if( target.getOverlapping(x) == ball_phy) {





but it doesn’t solve your problem, just looks better :P. If the for loop is getting called when there are not any overlapping as you suggest, then your getOverlappingCount() must be buggy.

[java]int x = target.getOverlappingCount()[/java]

^— Uses the size as index, you will inevitably get an out of bounds error with this, it should be target.getOverlappingCount()-1

Edit: … duh you are right, the loop is just completely useless ^^


Alright, I want my fireball to only go a certain distance before it disappears. How should I do that?

its probably better to do it time wise, where you use simpleUpdate’s tpf and add it up and check for certain # of seconds, i.e: for 5 seconds


public void updateProjectiles(float tpf){

time = time+tpf;

if(time>= 5){

remove blah;

time =0; // reset time




however for distance its same sort of thing, except you get control.GetPhysicsLocation - initial position, if you unsure look up “distance between vectors” on google, its pretty straightforward.

1 Like

Thanks so much. I feel stupid. :slight_smile:

No problem, where else can you seek guidance than on the forum :stuck_out_tongue: