public override void DrawGizmos(Vector3 position) { // TODO ship = GetComponent <AbstractShipDescriptor>(); Gizmos.color = Color.blue; Gizmos.DrawSphere(position, 0.5f); //Gizmos.DrawRay(position, new Vector3(StartingVelocity.x, StartingVelocity.y, 0) * GetComponent<AbstractShipDescriptor>().MaxShipSpeed); Vector3 currentPos = position; Vector3 newVelocity = StartingVelocity; foreach (var step in Steps) { Vector3 nextPos = currentPos + new Vector3(newVelocity.x, newVelocity.y) * step.TimeDelay * ship.MaxShipSpeed; Gizmos.DrawLine(currentPos, nextPos); currentPos = nextPos; newVelocity = step.Direction; //nextPos = currentPos + ; } Gizmos.DrawRay(currentPos, new Vector3(newVelocity.x, newVelocity.y) * ship.MaxShipSpeed); }
// Start is called before the first frame update protected virtual void Start() { ship = GetComponent <AbstractShipDescriptor>(); ship.VelocityVector = StartingVelocity; InterpolationTime = MaxInterpolationTime; }
// Start is called before the first frame update protected virtual void Start() { ship = GetComponent <AbstractShipDescriptor>(); ship.VelocityVector = StartingVelocity; }
private void DoControls() { if (Input.GetAxis("Cancel") > 0) { Application.Quit(); } float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); bool shouldFire = Input.GetAxis("Fire Weapons") > 0.0f && FireDisabledTime == 0.0f; bool stealShip = Input.GetAxis("Hack") > 0.0f; Vector2 velocity = new Vector2(horizontal, vertical); if (velocity.magnitude > 1) { velocity.Normalize(); } playerShip.VelocityVector = velocity; foreach (var w in playerShip.ShipWeaponList) { w.ShouldFire = shouldFire; } currentHackCooldown = Mathf.Max(0, currentHackCooldown -= Time.deltaTime); if (stealShip && currentHackCooldown <= 0) { // Try to steal enemy ship currentHackCooldown = MaxHackCooldown; // Raycast forward, hitting closest of either an enemy ship, or the level collider RaycastHit2D ray = Physics2D.Raycast(playerShip.transform.position, Vector2.up, 20, LayerMask.GetMask("LevelBoundary", "Enemies")); try { if (ray.collider) { GameObject otherObject = ray.collider.gameObject; AbstractShipDescriptor newShip = otherObject.GetComponent <AbstractShipDescriptor>(); if (newShip) { // Steal ship // Make new ship temporarily invincible newShip.IsInvincible = true; InvincibilityTime = MaxInvincibilityTime; // Disable controls FireDisabledTime = MaxControlDisableTime; // Delete enemy behavior, but NOT THE OBJECT var behavior = otherObject.GetComponent <AbstractEnemyBehavior>(); if (behavior) { Destroy(behavior); } // Safe swap of "playerShip". Possibly not necessary, but just in case var oldPlayerShip = playerShip; playerShip = newShip; // Switch ship's Rigidbody2D to Dynamic playerShip.gameObject.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic; // Grab current rotation to Slerp from from_rot = playerShip.transform.rotation; // Switch layer of new ship playerShip.gameObject.layer = LayerMask.NameToLayer("Player"); // Reset health of new ship playerShip.InitializeShipStats(); // TODO: a much better method of making Player ship's much more durable (maybe dependent on difficulty?) playerShip.CurrentHealth = playerShip.MaxHealth * 5; // Preserve ship through level-load DontDestroyOnLoad(playerShip.gameObject); // Set layer for all weapons' bullets foreach (var weapon in playerShip.ShipWeaponList) { weapon.BulletLayer = LayerMask.NameToLayer("PlayerBullets"); } // Now destroy the old ship // TODO: make destruction animation for all ships //Destroy(oldPlayerShip.gameObject); oldPlayerShip.CurrentHealth = -1; } List <Vector3> boltPositions = new List <Vector3> { playerShip.transform.position, ray.point }; // TODO: make bolt more jagged GameObject hackFX = Instantiate(HackFX); var lr = hackFX.GetComponent <LineRenderer>(); lr.SetPositions(boltPositions.ToArray()); } } catch (Exception e) { Debug.LogWarning("Need to add safety to this raycast: " + e.Message); } } }