This site requires JavaScript, please enable it in your browser!
Greenfoot back
Tioma7
Tioma7 wrote ...

2013/11/3

Bullet collision problem

Tioma7 Tioma7

2013/11/3

#
I set my bullet to move(50) it means that my bullet flye every frame by 50 cells and if my enemy is between tose 50 cells the bullet doesnt hit him it flyes away how to fix this?
danpost danpost

2013/11/3

#
Split the move of 50 into segments of 10 and collision check after each interval.
Tioma7 Tioma7

2013/11/3

#
danpost wrote...
Split the move of 50 into segments of 10 and collision check after each interval.
somethinlg like this: for(int i = bulletCurrentPosition; i <= bulletNextPosition; i += 10){ if(getOneIntersectingObject(Enemy.class) != null){ getWorld().removeObject(this); } }
danpost danpost

2013/11/3

#
You will need to move the bullet to each sub-location before performing the collision checking.
Tioma7 Tioma7

2013/11/3

#
danpost wrote...
You will need to move the bullet to each sub-location before performing the collision checking.
but how can i move bullet 5 times per 1 frame?
danpost danpost

2013/11/3

#
for (int n=0; n<5; n++) move(10);
Simply put, this would move the bullet 5 times in one frame. Of course, by itself, it is pretty much like calling 'move(50);'. But the idea of splitting up the move should be apparent.
Tioma7 Tioma7

2013/11/3

#
danpost wrote...
for (int n=0; n<5; n++) move(10);
Simply put, this would move the bullet 5 times in one frame. Of course, by itself, it is pretty much like calling 'move(50);'. But the idea of splitting up the move should be apparent.
Didnt know that is posible
Tioma7 Tioma7

2013/11/3

#
It would be better if i'd check every cell but i think i will lag much
danpost danpost

2013/11/3

#
I doubt the image of your enemy is smaller than 10 in its width or height.
Tioma7 Tioma7

2013/11/4

#
danpost wrote...
I doubt the image of your enemy is smaller than 10 in its width or height.
now when my bullet hits the enemy my game stops
Tioma7 Tioma7

2013/11/4

#
gets error actor is not in the world
Tioma7 Tioma7

2013/11/4

#
i solved that, had to add that if bullets hits enemy loop stops
You need to login to post a reply.