Created
March 24, 2022 16:57
-
-
Save archie426/b764cf6bcebd74f3845e0a4a5012602a to your computer and use it in GitHub Desktop.
POC for an anti-ballistics. This should be called instead of the raycast iteration unturned does. Generates only the final raycast step.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static RaycastInfo ShootStraight() | |
{ | |
//do full flat raycast as if the server had no ballistics | |
UseableGun gun = OptimizationVariables.MainPlayer.equipment.useable as UseableGun; | |
RaycastInfo r = DamageTool.raycast( | |
new Ray(OptimizationVariables.MainPlayer.transform.position, | |
OptimizationVariables.MainPlayer.transform.forward), gun.equippedGunAsset.range, | |
RayMasks.DAMAGE_CLIENT, OptimizationVariables.MainPlayer); | |
if (r.IsRaycastInvalid()) | |
return null; | |
//determine how many ballistic steps are required for the whole travel, except for the final one | |
int requiredSteps = (int) Math.Round(r.distance / gun.equippedGunAsset.ballisticSteps) - 1; | |
//select final step, original, absolute position: multiply the forward direction to account for the earlier steps and add in the originals player position | |
Vector3 targetFinalStepOrigin = OptimizationVariables.MainPlayer.transform.position + r.direction * requiredSteps; | |
//raycast from this final step to the target object which is bound to still exist, | |
RaycastInfo finalRaycast = DamageTool.raycast( | |
new Ray(targetFinalStepOrigin, | |
r.direction), 40f, //smaller just to optimise rather than using the whole distance, probably can be minimised further | |
RayMasks.DAMAGE_CLIENT, OptimizationVariables.MainPlayer); | |
return finalRaycast; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment