protected virtual bool OnCharge(Vector2 position, Vector2 direction, TankWeaponHolder holder, float chargeAmount) { bool canCharge = false; for (int i = 0; i < weaponFiringOffsets.Length; i++) { Quaternion rotation = holder.transform.rotation; Vector2 offsetPosition = position + (Vector2)(rotation * weaponFiringOffsets[i].position); Vector2 offsetDirection = Quaternion.Euler(0, 0, weaponFiringOffsets[i].angle) * direction; Collider2D overlapCollider = Physics2D.OverlapPoint(offsetPosition, CollideOnSpawnLayermask); if (overlapCollider) { continue; } WeaponData weaponData = new WeaponData() { ownerTank = holder.ownerTank, weapon = this, holder = holder }; projectile.OnCharge(position, direction, weaponData, chargeAmount); canCharge = true; } return(canCharge); }
private Vector2 AutoAimAtTargets(Vector2 position, Vector2 vector, TankWeaponHolder holder) { if (autoAimType == AutoAimType.None) { return(vector); } List <Collider2D> validTargets = FindAutoAimTargets(position, vector, holder); lastValidTargets = validTargets; if (validTargets.Count <= 0) { lastTarget = null; return(vector); } Collider2D target = ChooseClosestAutoAimTarget(position, vector, validTargets); lastTarget = target; Vector2 targetPoint = GetTarget(position, vector, target); Vector2 direction = (targetPoint - position).normalized; Vector2 calculatedVector = direction; calculatedVector = Vector2.Lerp(calculatedVector, vector, autoAimOffsetMagnitude); return(calculatedVector); }
protected virtual bool FireProjectile(Vector2 position, Vector2 direction, TankWeaponHolder holder) { bool wasFired = false; for (int i = 0; i < weaponFiringOffsets.Length; i++) { Quaternion rotation = holder.transform.rotation; Vector2 offsetPosition = position + (Vector2)(rotation * weaponFiringOffsets[i].position); Vector2 offsetDirection = Quaternion.Euler(0, 0, weaponFiringOffsets[i].angle) * direction; wasFired = true; Collider2D overlapCollider = Physics2D.OverlapPoint(offsetPosition, CollideOnSpawnLayermask); if (overlapCollider) { continue; } WeaponData weaponData = new WeaponData() { ownerTank = holder.ownerTank, weapon = this, holder = holder }; if (holder.ownerTank is PlayerTankManager) { weaponData.useCustomColour = true; weaponData.shotCustomColour = (holder.ownerTank as PlayerTankManager).colour; } projectile.OnFired(offsetPosition, offsetDirection, weaponData); } CameraShake.AddShake(shakeAmount, Quaternion.FromToRotation(Vector2.up, direction)); // Sorry jordan, I broke this and I have no idea what the value should be :( return(wasFired); }
protected override bool FireProjectile(Vector2 position, Vector2 direction, TankWeaponHolder holder) { Vector2 autoAimedDirection = AutoAimAtTargets(position, direction, holder); lastPosition = position; lastInputDirection = direction; lastDirection = autoAimedDirection; return(base.FireProjectile(position, autoAimedDirection, holder)); }
protected override bool FireProjectile(Vector2 position, Vector2 direction, TankWeaponHolder holder) { chargingVisualisations = holder.GetCurrentWeaponVisualisation().GetComponentsInChildren <LaserChargingVisualisation>(); for (int i = 0; i < chargingVisualisations.Length; i++) { chargingVisualisations[i].OnCharge(0); } return(base.FireProjectile(position, direction, holder)); }
public override void OnWeaponEquipted(TankWeaponHolder holder) { chargingVisualisations = holder.GetCurrentWeaponVisualisation().GetComponentsInChildren <LaserChargingVisualisation>(); if (holder.ownerTank is PlayerTankManager) { for (int i = 0; i < chargingVisualisations.Length; i++) { chargingVisualisations[i].SetColour((holder.ownerTank as PlayerTankManager).colour); chargingVisualisations[i].OnCharge(0); } } }
public virtual void OnFiringHold(Vector2 position, Vector2 direction, TankWeaponHolder holder) { if (holder.lastFired + firingDelay < Time.time) { if (holder.chargeUpElapsedTime < chargeUpDelay) { OnCharge(position, direction, holder, holder.chargeUpElapsedTime / chargeUpDelay); holder.chargeUpElapsedTime += Time.deltaTime; } else { FireProjectile(position, direction, holder); holder.OnWeaponFired(); holder.chargeUpElapsedTime = 0; } } }
private List <Collider2D> FindAutoAimTargets(Vector2 position, Vector2 vector, TankWeaponHolder holder) { List <Collider2D> validTargets = new List <Collider2D>(); Collider2D[] targets = Physics2D.OverlapCircleAll(position, autoAimRange, autoAimLayer); for (int i = 0; i < targets.Length; i++) { if (targets[i].transform.root == holder.transform.root) { continue; } Vector2 direction = ((Vector2)targets[i].transform.position - position).normalized; if (Vector2.Angle(direction, vector) <= autoAimArcAngle / 2) { validTargets.Add(targets[i]); } } return(validTargets); }
public virtual void OnFiringUp(Vector2 position, Vector2 direction, TankWeaponHolder holder) { holder.chargeUpElapsedTime = 0; OnCharge(position, direction, holder, holder.chargeUpElapsedTime / chargeUpDelay); }
public virtual void OnWeaponUnequipted(TankWeaponHolder holder) { }
public virtual void OnFiringDown(Vector2 position, Vector2 direction, TankWeaponHolder holder) { holder.chargeUpElapsedTime = 0; }