void Update() { if (isActive && Input.GetMouseButtonUp(0)) { projectile.AddForce(endInputPosition - startInputPosition); isActive = false; isControllable = false; } if (isControllable && Input.GetMouseButton(0)) { Vector3 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 inputPosition = new Vector2(worldPoint.x, worldPoint.y); if (Input.GetMouseButtonDown(0)) { if (colliderComponent == Physics2D.OverlapPoint(inputPosition)) { startInputPosition = transform.position; isActive = true; } } if (isActive) { endInputPosition = inputPosition; } } UpdateTrace(); }
IEnumerator Attack() { attacking = true; animator.SetTrigger("attack"); //Hardcoded attack animation delay yield return(new WaitForSeconds(3.1f)); //Shoots 3 bullets with a delay inbetween //Bullet go towards player position for (int i = 0; i < 5; i++) { //Create new projectile Projectile newBullet = Instantiate(bullet, transform.position, Quaternion.identity).GetComponent <Projectile>(); //Fix direction newBullet.damage = thisEnemy.strength; newBullet.LookAt(player.position, 0); newBullet.AddForce(player.position); yield return(new WaitForSeconds(0.2f)); } attacking = false; }
public void Shoot() { shooting?.Invoke(); turretAmmunition.DecreasteAmmuntionCount(1); GetNextShootTime(); Projectile projectile = Instantiate(projectilePrefab, projectileSpawnPoint.position, projectileSpawnPoint.rotation); projectile.AddForce(projectileSpawnPoint.right); shooted?.Invoke(); StopShooting(); }
public bool Tick(double newTime) { double parameter = GetParameterFromPosition(Projectile.Position); const double tolerance = 1e-9; if (parameter >= Path.FinalParameter || Math.Abs(parameter - Path.FinalParameter) < tolerance) { return(false); } Vector tangentDirection = TangentDirection(parameter); ConstrainPositionAndVelocity(parameter, tangentDirection); Vector acceleration = CalculateAcceleration(tangentDirection); Projectile.AddForce(Projectile.Mass * acceleration); Projectile.Update(newTime - Time); Time = newTime; return(true); }
IEnumerator Attack() { attacking = true; animator.SetTrigger("attack"); //Stop all Movement rb.velocity = new Vector2(0, 0); //Hardcoded animation length yield return(new WaitForSeconds(1f)); //Create new projectile Projectile newFireball = Instantiate(fireball, transform.position, Quaternion.identity).GetComponent <Projectile>(); //Fix direction newFireball.damage = thisEnemy.strength; newFireball.LookAt(player.position, 90); newFireball.AddForce(player.position); //Buffer between actions yield return(new WaitForSeconds(1f)); attacking = false; }