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); } }