#collision detection help
14 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include <vector>
int Pout;
int collisions(int PlayerX,int PlayerY,std::vector<int> startX, std::vector<int> startY, std::vector<int> endX, std::vector<int> endY,int Vel,bool vert = false, int id = 0,bool top = true, bool right = true, bool down = true, bool left = true) {
int Sx, Sy, Ex, Ey;
bool Xcol = false;
bool Ycol = false;
bool OUTcol = false;
switch (vert) {
case false:
while (!startX.empty()) {
Sx = startX.back();
Ex = endX.back();
startX.pop_back();
endX.pop_back();
if ((Sx-1 < PlayerX && PlayerX < Ex + 1)) {
Xcol = true;
}
std::cout << " X details: " <<"\n" << "Sx: " << Sx << "\n" << " Ex: " << Ex << "\n" << " PlayerX: " << PlayerX << " \n" << "\n";
}
break;
case true:
while (!startY.empty()) {
Sy = startY.back();
Ey = endY.back();
startY.pop_back();
endY.pop_back();
if ((Sy - 1 < PlayerY && PlayerY < Ey + 1)) {
Ycol = true;
}
std::cout << " Y details: " << "Sy: " << Sy << " Ey: " << Ey << " PlayerY: " << PlayerY <<" \n";
}
break;
}
OUTcol = ((Xcol && Ycol));
std::cout << OUTcol;
return OUTcol;
}```here is the code
and here is the console output:```0 Y details: Sy: 200 Ey: 232 PlayerY: 204
01 X details:
Sx: 200
Ex: 500
PlayerX: 234
this is extremely weird and unreadable and inefficient
OUTcol is Xcol and Ycol but since vert is false you never end up touching Ycol so it stays false and
anything && false = false
I'm not even sure if it's inefficient cause idk what exactly you're trying to do
I'd just rewrite that function into a lot of smaller ones
@pseudo wigeon Has your question been resolved? If so, run !solved :)
!solved