Zombies + Skeleton Physics arrow + aimbot
360 headhsot ezz
This commit is contained in:
parent
b3a87fb2a6
commit
bf010f3476
91 changed files with 28021 additions and 84 deletions
|
@ -5,14 +5,55 @@ public class AttackSkeleton : AttackHandler
|
|||
[SerializeField] private GameObject arrowPrefab;
|
||||
[SerializeField] private float arrowBaseSpeed;
|
||||
[SerializeField] private Transform spawnPos;
|
||||
[SerializeField] private bool directShot;
|
||||
|
||||
|
||||
public override bool Attack()
|
||||
{
|
||||
if (_timer > 0) return false;
|
||||
float launchAngle = findLaunchAngle();
|
||||
//print(launchAngle);
|
||||
// If target not reachable
|
||||
if (launchAngle < 0) return false;
|
||||
_timer = cooldown;
|
||||
|
||||
GameObject arrow = Instantiate(arrowPrefab, spawnPos.position, spawnPos.rotation);
|
||||
ArrowHandler arrowHandler = arrow.GetComponent<ArrowHandler>();
|
||||
arrowHandler.LaunchArrow(arrowBaseSpeed * spawnPos.forward);
|
||||
// In target <-> launcher + transform.up basis
|
||||
Vector2 localLaunchVector = arrowBaseSpeed * new Vector2(Mathf.Cos(launchAngle), Mathf.Sin(launchAngle));
|
||||
// Transform it in global basis
|
||||
AbstractUnit targetUnit = _minecraftUnit.MovementHandler.TargetUnit;
|
||||
Vector3 diffVector = Vector3.ProjectOnPlane(targetUnit.transform.position - spawnPos.position, Vector3.up);
|
||||
|
||||
Vector3 launchVectorNormalized = (localLaunchVector.x * diffVector.normalized + localLaunchVector.y * Vector3.up).normalized;
|
||||
arrowHandler.LaunchArrow(launchVectorNormalized * arrowBaseSpeed);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private float findLaunchAngle()
|
||||
{
|
||||
// Source : https://en.wikipedia.org/wiki/Projectile_motion#Angle_%CE%B8_required_to_hit_coordinate_(x,_y)
|
||||
|
||||
AbstractUnit targetUnit = _minecraftUnit.MovementHandler.TargetUnit;
|
||||
Vector3 diffVector = Vector3.ProjectOnPlane(targetUnit.transform.position - spawnPos.position, Vector3.up);
|
||||
|
||||
float x = Vector3.ProjectOnPlane(diffVector, Vector3.up).magnitude;
|
||||
float y = diffVector.y;
|
||||
float g = Physics.gravity.magnitude;
|
||||
float v = arrowBaseSpeed;
|
||||
float v_sqr = v * v;
|
||||
//print("x : " + x);
|
||||
|
||||
float inside_sqrt_root = v_sqr*v_sqr - g*(g*x*x + 2*y*v_sqr);
|
||||
if (inside_sqrt_root < 0.0f) return -1f; // Can't reach target
|
||||
|
||||
// directShot is the smallest angle, undirectShot shot is the biggest angle
|
||||
float numerator = directShot ? v_sqr - Mathf.Sqrt(inside_sqrt_root) : v_sqr + Mathf.Sqrt(inside_sqrt_root);
|
||||
float inside_arctan = numerator / (g * x);
|
||||
print(inside_arctan);
|
||||
return Mathf.Atan(inside_arctan);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue