// Use this for initialization void Start() { this.player = PlayerController.instance; this.rb2d = this.GetComponent <Rigidbody2D> (); this.ranged = this.GetComponent <RangedAttacker> (); this.animator = this.GetComponent <Animator> (); }
/** * Spawns a unit and places it on the right side of the screen. * The unit itself determines when it is deleted. It is not based off of the delay time here. * Can mess around with the transform.position as desired. * * Note: for funny 3d way of facing target, use: * attackerObject.transform.LookAt(targetObject.transform); * * @source https://youtu.be/E7gmylDS1C4?t=434 */ private void SpawnAttacker() { GameObject attackerObject = Instantiate(rangedAttackerPrefab); GameObject targetObject = Instantiate(markerPrefab); activeAttacker = attackerObject.GetComponent <RangedAttacker>(); activeTarget = targetObject.GetComponent <RangedAttacker>(); attackerObject.transform.position = new Vector2(screenBounds.x - 1, screenBounds.y - 1); activeAttacker.lifespan = attackDelay; targetObject.transform.position = new Vector3(attackPoint.x, attackPoint.y, targetObject.transform.position.z); activeTarget.lifespan = attackDelay; // check if this attacker wants to align horizontally with its target if (activeAttacker.alignsWithTargetHorizontally) { attackerObject.transform.position = new Vector2(attackerObject.transform.position.x, targetObject.transform.position.y); } // check if this attacker wants to align vertically with its target if (activeAttacker.alignsWithTargetVertically) { attackerObject.transform.position = new Vector2(targetObject.transform.position.x, attackerObject.transform.position.y); } }
// Use this for initialization void Start() { this.rb2d = this.GetComponent <Rigidbody2D> (); this.animator = this.GetComponent <Animator> (); this.meleeAttacker = this.GetComponent <MeleeAttacker> (); this.rangedAttacker = this.GetComponent <RangedAttacker> (); this.toolUser = this.GetComponent <ToolUser> (); StartCoroutine(StartAnimations()); // Give player starting items // this.inventory.Add("sword"); }
// Use this for initialization void Start() { this.rb2d = this.GetComponent <Rigidbody2D> (); this.animator = this.GetComponent <Animator> (); this.meleeAttacker = this.GetComponent <MeleeAttacker> (); this.rangedAttacker = this.GetComponent <RangedAttacker> (); this.toolUser = this.GetComponent <ToolUser> (); this.sword = gameObject.AddComponent <AudioSource> (); this.sword.clip = Resources.Load("Sounds/SwordSwing1") as AudioClip; print(this.sword); // Give player starting items //this.inventory.Add("sword"); }
// Use this for initialization void Start() { this.rb2d = this.GetComponent<Rigidbody2D> (); this.animator = this.GetComponent<Animator> (); this.meleeAttacker = this.GetComponent<MeleeAttacker> (); this.rangedAttacker = this.GetComponent<RangedAttacker> (); this.toolUser = this.GetComponent<ToolUser> (); StartCoroutine (StartAnimations()); // Give player starting items // this.inventory.Add("sword"); }
public void setWeapon(RangedAttacker rangedWep) { this.rangedWeapon = rangedWep; }
// Use this for initialization void Start() { this.rb2d = this.GetComponent<Rigidbody2D> (); this.animator = this.GetComponent<Animator> (); this.meleeAttacker = this.GetComponent<MeleeAttacker> (); this.rangedAttacker = this.GetComponent<RangedAttacker> (); this.toolUser = this.GetComponent<ToolUser> (); this.sword = gameObject.AddComponent<AudioSource> (); this.sword.clip = Resources.Load ("Sounds/SwordSwing1") as AudioClip; print (this.sword); // Give player starting items //this.inventory.Add("sword"); }
protected override void Update() { base.Update(); is_aimed = false; Vector3 position = RangedAttacker.BarrelTip; Vector3 displacement = Target.Position - position; Vector3 direction = displacement.normalized; Vector3 flat_up = new Vector3(0, 1, 0); Vector3 flat_direction = direction.InPlane(flat_up).normalized; Vector3 surface_normal = Scene.Main.World.Asteroid.GetSurfaceNormal(position); float flat_angle; if (!(RangedAttacker is ProjectileAttacker)) { flat_angle = Mathf.Atan(flat_up.Dot(direction) / flat_direction.Dot(direction)); } else { ProjectileAttacker projectile_attacker = RangedAttacker as ProjectileAttacker; float squared_velocity = Mathf.Pow(projectile_attacker.ProjectileVelocity, 2); float horizontal_distance = displacement.Dot(flat_direction); float vertical_distance = Target.Position.y - position.y; float gravity = Scene.Main.World.Asteroid.SurfaceGravity; float root = squared_velocity * squared_velocity - gravity * (gravity * Mathf.Pow(horizontal_distance, 2) + 2 * vertical_distance * squared_velocity); if (root < 0) { RangedAttacker.FiringAngle = Mathf.PI / 4; return; } root = Mathf.Sqrt(root); if (!projectile_attacker.UseHighFiringAngle) { root *= -1; } flat_angle = Mathf.Atan((squared_velocity + root) / (gravity * horizontal_distance)); } Vector3 target_firing_direction = GetFiringDirection(flat_direction, flat_up, flat_angle); Vector3 target_forward = target_firing_direction.InPlane(surface_normal).normalized; float target_angle = target_firing_direction.AngleBetween(target_forward); if (target_firing_direction.y < target_forward.y) { target_angle *= -1; } target_angle = Mathf.Max(target_angle, RangedAttacker.ShallowestFiringAngle); target_angle = Mathf.Min(target_angle, RangedAttacker.SteepestFiringAngle); //Turn if (RangedAttacker.HasComponent <Motile>()) { RangedAttacker.GetComponent <Motile>().Turn(target_forward); } //Point RangedAttacker.FiringAngle = target_angle; if (target_firing_direction.Dot(RangedAttacker.FiringDirection) > 0.9999f) { is_aimed = true; } }