public IEnumerator Reload() { int currentTotalAmmo = weaponData.GetInventoryAmmo(); if (weaponData.GetClipAmmo() < weaponData.GetMaxClipAmmo() && !isReloading && currentTotalAmmo > 0) { int ammoSpent = weaponData.GetMaxClipAmmo() - weaponData.GetClipAmmo(); isReloading = true; animator.SetBool("reload", true); Debug.Log("Reloading"); //Debug.Log(m_CurrentClipInfo.Length); yield return(new WaitForSeconds(reloadTime)); int clipAmmo = (weaponData.GetMaxClipAmmo() <= currentTotalAmmo + weaponData.GetClipAmmo()) ? weaponData.GetMaxClipAmmo() : (weaponData.GetClipAmmo() + currentTotalAmmo) % weaponData.GetMaxClipAmmo(); if (this is HitScan) { HitScan temp = (HitScan)this; temp.ResetBulletSpread(); } weaponData.SetClipAmmo(clipAmmo); weaponData.ChangeInventoryAmmo(-ammoSpent); Debug.Log("Done reloading"); animator.SetBool("reload", false); UpdateAmmoInfo(); } isReloading = false; }
public void Shoot(int muzzle) { Transform pos = MuzzleSpots[muzzle]; if (MuzzleFlashPrefab != null) { var spawned = PoolObject.Spawn(MuzzleFlashPrefab); spawned.transform.position = pos.position; spawned.transform.rotation = pos.rotation; } Vector2 direction = pos.right; float angle = direction.ToAngle(); bool right = Random.value <= 0.5f; angle += Random.Range(AngleOffset.x, AngleOffset.y) * 0.5f * (right ? 1f : -1f); direction = angle.ToDirection(); switch (Type) { case ProjectileType.HITSCAN: HitScan.Shoot(pos.position, direction, HitscanRange, 10f); // TODO allow custom damage here and in spawned projectiles. break; case ProjectileType.PROJECTILE: if (JNet.IsServer) { Projectile.Spawn(pos.position, direction, ProjectileSpeed); } break; } }
private void Update() { if (weapon != null && weapon is HitScan) { HitScan temp = (HitScan)weapon; if (!firing) { temp.DecrementBulletSpread(); } else { temp.IncrementBulletSpread(); } // Debug.Log(firing); } }
public void applyBlink(float elapsedTime, Player player, Vector3 move) { BoundingBox playerBoundingBox = player.getBoundingBox(); Vector3 cent = center(playerBoundingBox); //fix the move with a hitscan HitScan hs = hitscan(cent, Vector3.Normalize(move), null); if (hs != null && hs.Distance() < Math.Sqrt(Vector3.Dot(move, move))) { move = Vector3.Normalize(move) * hs.Distance() + hs.collisionFace.plane.getNormal() * 70; } Vector3 offset = center(playerBoundingBox) - player.getPosition(); Vector3 playerRadius = size(playerBoundingBox) * 0.5f; Vector3 basePoint = toESpace(playerRadius, cent); Vector3 evelocity = toESpace(playerRadius, move); Vector3 pos = collideWithWorld(playerRadius, basePoint, evelocity, 0, player); player.setPosition(toWorldSpace(playerRadius, pos) - offset); }
public void splashDamage(Vector3 position, float size, float damage) { foreach (Agent a in core.allAgents()) { if (a.spawnTime > 0) { continue; } BoundingBox bb = a.getBoundingBox(); Vector3 cent = bb.Min + (bb.Max - bb.Min) * 0.5f; float dist = Vector3.Distance(cent, position); if (dist < size) { //do hitscan check HitScan hs = hitscan(position, cent - position, null); if (hs == null || hs.Distance() > dist) { a.health -= (int)Math.Ceiling(damage * Math.Pow(1 - dist / size, 0.5)); } } } }