Skip to main content
Removed answer from question and placed it in the answer section
Source Link
Darcy
  • 81
  • 8

CONCLUSION: I am happy to say that I have squashed the bug. The visualisations really aided me and I strongly recommend anybody struggling with anything to try and get whatever it is your working on onto the screen. Now for how I fixed the bug and what it was. The reason it was not properly setting the min and max projections is due to the ProjectOntoAxes method. For the min and max values, I initially set them to the complete opposite values via the lines

float min = float.MaxValue;
float max = float.MinValue;

This was so that they were guaranteed to be set to one of the corners. Now the bug causing lines are the if and else if conditional statements inside the for loop. What was happening was that if the very first corner checked was actually the maximum value, it would actually always set off the first if statement checking if it is less than the minimum because the minimum is literally the highest value possible. Due to the next if having an else before it, it would not be checked and thus the max value will not actually be set to the real max value. Therefore the simple fix was to remove the else and just have to regular if statements, this allows for the case where if the first corner checked is actually going to end up being the maximum, it will still trigger the second if statement for setting the maximum value.

This:

if (res < min) {
    min = res;
} else if (res > max) {
    max = res;
}

became this:

if (res < min) {
    min = res;
} if (res > max) {
    max = res;
}

CONCLUSION: I am happy to say that I have squashed the bug. The visualisations really aided me and I strongly recommend anybody struggling with anything to try and get whatever it is your working on onto the screen. Now for how I fixed the bug and what it was. The reason it was not properly setting the min and max projections is due to the ProjectOntoAxes method. For the min and max values, I initially set them to the complete opposite values via the lines

float min = float.MaxValue;
float max = float.MinValue;

This was so that they were guaranteed to be set to one of the corners. Now the bug causing lines are the if and else if conditional statements inside the for loop. What was happening was that if the very first corner checked was actually the maximum value, it would actually always set off the first if statement checking if it is less than the minimum because the minimum is literally the highest value possible. Due to the next if having an else before it, it would not be checked and thus the max value will not actually be set to the real max value. Therefore the simple fix was to remove the else and just have to regular if statements, this allows for the case where if the first corner checked is actually going to end up being the maximum, it will still trigger the second if statement for setting the maximum value.

This:

if (res < min) {
    min = res;
} else if (res > max) {
    max = res;
}

became this:

if (res < min) {
    min = res;
} if (res > max) {
    max = res;
}
Fixed the bug
Source Link
Darcy
  • 81
  • 8

CONCLUSION: I am happy to say that I have squashed the bug. The visualisations really aided me and I strongly recommend anybody struggling with anything to try and get whatever it is your working on onto the screen. Now for how I fixed the bug and what it was. The reason it was not properly setting the min and max projections is due to the ProjectOntoAxes method. For the min and max values, I initially set them to the complete opposite values via the lines

float min = float.MaxValue;
float max = float.MinValue;

This was so that they were guaranteed to be set to one of the corners. Now the bug causing lines are the if and else if conditional statements inside the for loop. What was happening was that if the very first corner checked was actually the maximum value, it would actually always set off the first if statement checking if it is less than the minimum because the minimum is literally the highest value possible. Due to the next if having an else before it, it would not be checked and thus the max value will not actually be set to the real max value. Therefore the simple fix was to remove the else and just have to regular if statements, this allows for the case where if the first corner checked is actually going to end up being the maximum, it will still trigger the second if statement for setting the maximum value.

This:

if (res < min) {
    min = res;
} else if (res > max) {
    max = res;
}

became this:

if (res < min) {
    min = res;
} if (res > max) {
    max = res;
}

CONCLUSION: I am happy to say that I have squashed the bug. The visualisations really aided me and I strongly recommend anybody struggling with anything to try and get whatever it is your working on onto the screen. Now for how I fixed the bug and what it was. The reason it was not properly setting the min and max projections is due to the ProjectOntoAxes method. For the min and max values, I initially set them to the complete opposite values via the lines

float min = float.MaxValue;
float max = float.MinValue;

This was so that they were guaranteed to be set to one of the corners. Now the bug causing lines are the if and else if conditional statements inside the for loop. What was happening was that if the very first corner checked was actually the maximum value, it would actually always set off the first if statement checking if it is less than the minimum because the minimum is literally the highest value possible. Due to the next if having an else before it, it would not be checked and thus the max value will not actually be set to the real max value. Therefore the simple fix was to remove the else and just have to regular if statements, this allows for the case where if the first corner checked is actually going to end up being the maximum, it will still trigger the second if statement for setting the maximum value.

This:

if (res < min) {
    min = res;
} else if (res > max) {
    max = res;
}

became this:

if (res < min) {
    min = res;
} if (res > max) {
    max = res;
}
Identified the problem
Source Link
Darcy
  • 81
  • 8

UDPATE: I have added code to visualise the projections and axes to see what is going on, and it appears that the projection code is not properly selecting the correct minimum and maximum values. I will try to figure out why now. (Purple lines are player projections and orange is the projections of that tile I am standing on, the top left one and the player axes can be visualised via the white lines at the origin)

enter image description here

UDPATE: I have added code to visualise the projections and axes to see what is going on, and it appears that the projection code is not properly selecting the correct minimum and maximum values. I will try to figure out why now. (Purple lines are player projections and orange is the projections of that tile I am standing on, the top left one and the player axes can be visualised via the white lines at the origin)

enter image description here

Source Link
Darcy
  • 81
  • 8
Loading