private void UpdateProjectiles() { currentProjectiles.RemoveAll(x => x == null); foreach (Projectile projectile in currentProjectiles) { if (projectile == null || !projectile.gameObject.activeSelf) { continue; } if (projectile.target != null) { // Rotate projectile towards target Vector2 dirToTarget = (projectile.target.position - projectile.transform.position).normalized; Quaternion targetRot = Quaternion.Euler(0, 0, MKUtility.CalcDir2D(dirToTarget)); projectile.transform.rotation = Quaternion.Lerp(projectile.transform.rotation, targetRot, Time.deltaTime * projectile.projectileData.rotationSpeed); } if (projectile.projectileData.speed != 0) { projectile.transform.Translate(Vector2.right * projectile.projectileData.speed * Time.deltaTime); } } }
private void DirectMovement() { // Set velocity to rigidbody Rb2D.velocity = direction * speed * appliedSprintMultiplier; if (rotationType == RotationType.RotateTowardsTarget) { Rb2D.rotation = MKUtility.CalcDir2D(Rb2D.position, rotationTarget); } else if (rotationType == RotationType.RotateTowardsMovement) { Rb2D.rotation = MKUtility.CalcDir2D(direction); } }
private void SpawnCruiserAtRandomPos(bool showArrivalMessage = true) { cruisers.RemoveAll(x => x == null); Vector2 pos = MKUtility.GetRandomPositionInBounds(arenaBounds.bounds, gameData.spawningPadding); Cruiser cruiser = Instantiate(gameData.cruiserPrefab, pos, Quaternion.identity); cruisers.Add(cruiser); if (showArrivalMessage) { UIManager.PromptIfEmpty(2f, MK.UI.TransitionPreset.ScaleIn, "An enemy cruiser has arrived!"); AudioManager.PlayOneShot(AudioData.cruiserMessageAudio, AudioData.cruiserMessageVolume); } DestroyWorldObjectsAroundPos(pos, gameData.cruiserClearRadius); }
private void OnTriggerEnter2D(Collider2D collision) { if (MKUtility.CheckIfLayerIsWithinMask(collision.transform.gameObject.layer, layerMask)) { Destructible destructible = collision.gameObject.GetComponent <Destructible>(); if (destructible) { destructible.Hurt(projectileData.damage); } onHit.Invoke(); if (projectileData.destroyOnHit) { onDestroy.Invoke(); Destroy(gameObject); } } }