#Horizontal Velocity Calculator inaccuracies
1 messages ยท Page 1 of 1 (latest)
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
ke sure the calculations are accurate.
Here are some possible reasons why your Horizontal Velocity Calculator may be producing inaccurate results:
-
Calculation errors: Double-check your code to ensure that the mathematical formulas used to calculate horizontal velocity are correct. Even a small error in the calculation can lead to significant discrepancies in the final result.
-
Rounding errors: Make sure you are not rounding off intermediate results too early in the calculation process. Round off only the final result to avoid cumulative errors.
-
Data type issues: Check that you are using appropriate data types for variables involved in the calculation. Using floating-point numbers instead of integers can help improve accuracy.
-
Input data inconsistencies: Ensure that the input data provided to the calculator is accurate and consistent. Any inconsistencies or inaccuracies in the input values can affect the final output.
-
Testing and validation: Run extensive tests on your calculator with different input values to identify any patterns or trends in inaccuracies. This can help pinpoint specific areas of improvement in your code.
By addressing these potential issues and fine-tuning your Horizontal Velocity Calculator code, you should be able to improve its accuracy and produce more reliable results for your anticheat system.
I uploaded your attachments as Gist.
I uploaded your attachments as Gist.
package ac.kosko.vigilanceAnticheat.Processor;
import ac.kosko.vigilanceAnticheat.Packets.PlayerData;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class HorizontalVelocityChecker {
private static final Logger LOGGER = Logger.getLogger(HorizontalVelocityChecker.class.getName());
private PlayerData playerData;
private double lastX;
private double lastZ;
private long lastPacketReceiveTime;
private float horizontalVelocity;
public HorizontalVelocityChecker(PlayerData playerData) {
this.playerData = playerData;
this.lastX = 0.0;
this.lastZ = 0.0;
this.lastPacketReceiveTime = 0L;
this.horizontalVelocity = 0.0f;
LOGGER.info("HorizontalVelocityChecker initialized for player " + playerData.getUuid());
}
public void processPacket(double x, double z, long receiveTime) {
if (this.lastPacketReceiveTime != 0L) {
double deltaX = x - this.lastX;
double deltaZ = z - this.lastZ;
double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
long timeDiff = receiveTime - this.lastPacketReceiveTime;
double timeDiffSeconds = timeDiff / 1000.0; // Convert milliseconds to seconds
double horizontalVelocity = distance / timeDiffSeconds;
this.horizontalVelocity = (float) horizontalVelocity;
} else {
LOGGER.info("First packet received, skipping velocity calculation");
}
this.lastX = x;
this.lastZ = z;
this.lastPacketReceiveTime = receiveTime;
}
public double getHorizontalVelocity() {
Player player = Bukkit.getPlayer(this.playerData.getUuid());
player.sendMessage("Returning horizontal velocity: " + this.horizontalVelocity + " m/s");
return this.horizontalVelocity;
}
}
i know its a lot of code and compl;icated for somone to help so i dont expect anyone to reply as it would take them a while to read understand the code and help find the problem
I assume you're using data types with the most precision?
I would put down some print statements to see the results of each calculation and where it's going wrong
Time to learn how to incorporate unit testing into your project.
Did you use the same formula or even same code as the game ?
yeah when my proccessor proccess them and stores it in the player data class it is usign the most precise data type
i am i can see the caclulation and every 2 ticks i get a message detailing the calculated speed and it is sayign 5.7xxxxx m/s sometimes 5.8xxxxxm/s
but the correct value is 5.6xxxxm/s
no this is a plugin so it doesnt need the same equasion i am trying to use the most precise equasion to result the exact value then compare it in a list of know trues etc but thats for later on
but yes minecraft runs in java and i am usign the correct JDK for the version of miencraft i am running
plus the correxct protocol libs api and the correct spigot api
the problem doesnt seem to be with any of that tho maybe i am casting smth to the wrogn class maybe my equasion ios missing smth out idkl thats why i posted here to see if asomone could help
i have found a solution i implimented a Kalman filter that also includes the calculated velocity as an input at that has helped signifcantly