We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i was wondering if anyone could help in regards to in regards collision detection void collisionDetection(){ for(int i = 0; i < aesteroidBelt.size(); i++){ Aesteroid current = aesteroidBelt.get(i);
for(int b = 0; b < bullets.size(); b++)
{
Bullet currentBullet = bullets.get(b);
if(dist()){
bullets.remove(b);
aesteroidBelt.remove(i);
Cant figure out the values to use for keeps telling me that booleans are not accept and only floats are.
These are the variables i have
int n=12;
PVector ship;
//Initilaizes Variables used
float bulletSpeed = 5;
float angle = 0;
float targetAngle = 0;
float rotation = 0.05;
float xSpeed = random(0.6, 2.5);
float ySpeed = random(0.6, 2.5);
float x = random(1, 590);
float y = random(1, 390);
My Aesteroids are also a random PVector every time you run this code(part which i am stuck on)
Answers
if(dist()){
dist
expects for parameters: currentBullet.x,currentBullet.y and x,y for the Asteroidto use remove() you must loop backward through the bullets. Change the for-loop
Forgot to remove the x and y variables.
this is the function im using to implement the balls and i cant seem to get the x and y coordinates for them
I altered the code in other to use those x and y variables and all the balls started spawning in the same spot give or take a few and would stick to the walls and not bounce
POST YOUR ENTIRE CODE
Normally it's x,y not y,x
yes
https://forum.Processing.org/two/discussions/tagged/backwards
Altered function in accordance to backwards like in the ArrayList and still no luck
If i add !=0 every shot will remove so im guessing theres an issue with the logical / spacing?
http://www.JeffreyThompson.org/collision-detection/point-circle.php
http://studio.ProcessingTogether.com/sp/pad/export/ro.9K-kjhuONcJDZ/latest
I dont quite understand his implementation? is there anyway you could edit mine in accordance to what is wrong?
You need to use
break
after the double remove(). L-)And you need to implement your own checkHit() method too. >-)
How would i go about that? isnt that what the dist function is?
Collision is 1 of the most requested themes is this forum. You can always check the old answers:
https://forum.Processing.org/two/discussions/tagged?Tag=#collisions
Or read about it: http://www.JeffreyThompson.org/collision-detection/index.php
Or try to understand my own implementation: :P
You need to implement backward removal. For collision detection, you need to understand the basic concept. You check the distance between the two object's center against the sum of their radii. This is valid for the circular problem only.
Kf
Wow thankyou very much