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
|
@ -8,13 +8,19 @@ public class ArrowHandler : MonoBehaviour
|
|||
{
|
||||
[SerializeField] private float baseDamage;
|
||||
[SerializeField] private float baseKnockback;
|
||||
public Rigidbody _rigidBody;
|
||||
private Rigidbody _rigidBody;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidBody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Align with speed
|
||||
if (_rigidBody.linearVelocity.magnitude >= 1f) transform.forward = _rigidBody.linearVelocity.normalized;
|
||||
}
|
||||
|
||||
public void LaunchArrow(Vector3 baseSpeed)
|
||||
{
|
||||
_rigidBody.linearVelocity = baseSpeed;
|
||||
|
@ -33,5 +39,7 @@ public class ArrowHandler : MonoBehaviour
|
|||
}
|
||||
unit.TakeDamage(baseDamage);
|
||||
}
|
||||
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class AttackHandler : MonoBehaviour
|
|||
[SerializeField] protected float knockbackVerticalForce;
|
||||
|
||||
protected float _timer;
|
||||
private MinecraftUnit _minecraftUnit;
|
||||
protected MinecraftUnit _minecraftUnit;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
|
|
@ -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