private void Start() { input = GetComponent <ShipInput>(); physics = GetComponent <ShipPhysics>(); mainCamera = Camera.main.GetComponent <CameraBehaviour>(); alive = true; InitColliders(); inputState = State.playerInputs; lastState = State.playerInputs; deathUI.SetActive(false); transform.position = GameObject.Find("worldCenter").transform.position - new Vector3(0f, 0f, GameObject.Find("worldCenter").GetComponent <outZone>().GetRadius() * 0.95f); possibleTargets = new List <GameObject>(); selectedTarget = null; lockTimer = 0f; GameObject[] allTurrets = GameObject.FindGameObjectsWithTag("TurretT2"); foreach (GameObject go in allTurrets) { if (go.transform.root.gameObject == gameObject) { turret = go; GetComponentInChildren <WeaponShootManager>().AddTurret(turret); maxHealth = 2000f; health = maxHealth; break; } } }
private void Awake() { physics = new ShipPhysics(GetComponent <Rigidbody>(), ref Specs); Pilot.ownShip = this; Pilot.ownTarget = GetComponent <Target>(); Pilot.Init(); finalDestructionCountdown = Random.Range(2f, 3f); }
// Start is called before the first frame update void Start() { shipState = 0; al = GetComponent <Altitude>(); input = GetComponent <ShipInput>(); physics = GetComponent <ShipPhysics>(); rb = GetComponent <Rigidbody>(); }
private void initSpeed() { // 10% randomisation. float randY = Global.Instance.rand.Next(700 - (700 / 10), 700 + (700 / 10)); float randX = Global.Instance.rand.Next(1400 - (1400 / 10), 1400 + (1400 / 10)); randY *= 0.01f; randX *= 0.01f; Yaxis = new ShipPhysics(randY, 0.1f, randY); Zaxis = new ShipPhysics(randX, 0.1f, randX); }
private void Awake() { aiInput = new ShipAI(this, this.GetComponent <Rigidbody>()); physics = new ShipPhysics(this, this.GetComponent <Rigidbody>()); if (leader != null) { leader.subordinates.Add(this); leader.isLeader = true; inSquad = true; leader.inSquad = true; } }
//________________________________________ Ramming ________________________________________// public void DetermineRammingSeverity(Collision collision) { if (!ShouldProcessRamming) { ShouldProcessRamming = true; return; } ShipPhysics otherShipPhysics = collision.gameObject.GetComponent <ShipPhysics>(); otherShipPhysics.ShouldProcessRamming = false; Vector3 rammedVelocity = otherShipPhysics.RigidBodyVelocity; Vector3 velocity = RigidBodyVelocity; float dot = Vector3.Dot(transform.forward, (collision.contacts[0].point - transform.position).normalized); float collisionAngle = Mathf.Abs(Vector3.SignedAngle(transform.forward, collision.gameObject.transform.forward, Vector3.up)); ShipPhysics hitter = dot < 0.7f ? otherShipPhysics : this; ShipPhysics target = dot < 0.7f ? this : otherShipPhysics; float speedDifferenceSqr = (velocity - rammedVelocity).sqrMagnitude; // Check wether the angle difference is big enough OR if the speed difference is big enough if (collisionAngle >= MinRamImpactAngle && collisionAngle <= 180 - MinRamImpactAngle) { //PrintRam(gameObject.name, "Big V Target", hitter.name, target.name, collisionAngle, dot, speedDifferenceSqr); DoCameraShakeIfPlayer(collision.gameObject); target.PushShipInDirection(hitter.RigidBodyVelocity, hitter.RigidBodyVelocity.sqrMagnitude, _pushMagnitude); hitter.SlowDownAfterImpact(speedDifferenceSqr); SpawnEffect(RamEffect, collision.contacts[0].point, Quaternion.Inverse(hitter.transform.rotation), target.RammingVelocity * target.RammingDirection); } else if (speedDifferenceSqr >= _minRamSpeedDifference * _minRamSpeedDifference) { //PrintRam(gameObject.name, "Big V Big", hitter.name, target.name, collisionAngle, dot, speedDifferenceSqr); DoCameraShakeIfPlayer(collision.gameObject); StopMoving(); PushShipInDirection(rammedVelocity, rammedVelocity.sqrMagnitude, _bigPushMagnitude); otherShipPhysics.StopMoving(); otherShipPhysics.PushShipInDirection(velocity, velocity.sqrMagnitude, _bigPushMagnitude); SpawnEffect(RamEffect, collision.contacts[0].point, Quaternion.identity, Vector3.zero); } else { //PrintRam(gameObject.name, "Small", hitter.name, target.name, collisionAngle, dot, speedDifferenceSqr); hitter.SlowDownAfterImpact(speedDifferenceSqr); } }
private void Awake() { animacion = GetComponent <Animator>(); input = GetComponent <ShipInput>(); physics = GetComponent <ShipPhysics>(); }
// Use this for initialization void Start() { phys = GetComponentInParent <ShipPhysics>(); render = GetComponent <SpriteRenderer>(); }
private void Awake() { input = GetComponent <ShipInput>(); physics = GetComponent <ShipPhysics>(); }
// Use this for initialization void Start() { shooting = GetComponent <RockShooting>(); physics = GetComponent <ShipPhysics>(); phys = GetComponent <PhysicsVariables>(); }
private void Awake() { aiInput = GetComponent <ShipAI>(); physics = GetComponent <ShipPhysics>(); }
// Use this for initialization void Start() { physics = GetComponent <ShipPhysics>(); }
void Update() { //turning the ship if (leftClick == 1) { control.Turn(); //arcArrow.Turn (); } if (leftClick == 2) { arcArrow.launchArrow.transform.position = finalCoor; } /////////////////////////////////////For rotating the ship//////////////////////////////////////// if (Input.GetMouseButtonDown(0) && leftClick == 0) { Vector2 mousePosition = cam.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hitInfo = Physics2D.Raycast(mousePosition, Vector2.zero); if (hitInfo.collider != null) { Debug.Log("hit"); //set the gameobject to the ship if it's a hit string name = hitInfo.collider.gameObject.name; control = GameObject.Find(name).GetComponent <ShipControls>(); control.SelectedShip(hitInfo.collider.gameObject); phys = GameObject.Find(name).GetComponent <ShipPhysics> (); rigidbody = GameObject.Find(name).GetComponent <Rigidbody2D>(); phys.SetRigid(rigidbody); phys.SetCurrent(hitInfo.collider.gameObject); leftClick++; } else { Debug.Log("No hit"); } } //if bracket ///////////////////////////////////For Selecting the direction///////////////////////////////////// else if (Input.GetMouseButtonDown(0) && leftClick == 1) { Debug.Log("LeftClick1"); leftClick++; //Gets the position of ship and mouse Vector3 shipPos = control.GetShipPosition(); Vector2 mousePos = cam.ScreenToWorldPoint(Input.mousePosition); //Move launch arc to clicked ship //arcArrow.ChangeArcPos(shipPos); //CalculateOffset (shipPos, mousePos); //math for launch arc float theta = ConeDirection(mousePos, shipPos); float coneStart = theta - coneWidth / 2; float coneEnd = theta + coneWidth / 2; tempDirection = theta; float spacing = Mathf.PI / 180; //begin moving launch arrow dirThread = new Thread(() => startDirectionCounter(spacing, coneStart, coneEnd, shipPos)); dirThread.Start(); } ////////////////////////////////////For selection power/////////////////////////// else if (Input.GetMouseButtonDown(0) && leftClick == 2) { dirThread.Abort(); leftClick++; powerInc = true; } //On the last click, we get the final power and move the ship else if (Input.GetMouseButtonDown(0) && leftClick == 3) { leftClick = 0; Debug.Log("Power:" + finalPower.ToString()); Debug.Log("Angle:" + tempDirection.ToString()); powerInc = false; powerDec = false; click = true; moveShip(50); finalPower = 0; } if (powerInc) { finalPower += Time.deltaTime * barSpeed; //stops the power bar from going past its max length finalPower = Mathf.Clamp(finalPower, 0, fullWidth); //start decreasing power when the power reaches the maximum if (finalPower == fullWidth) { powerInc = false; powerDec = true; } powerBar.UpdatePower(finalPower, fullWidth); //set the width of the GUI Texture equal to that power value //GUITexture bar = GameObject.Find("powerBar").GetComponent<GUITexture>(); } if (powerDec) { finalPower -= Time.deltaTime * barSpeed; //stops the power bar from goin past 0 finalPower = Mathf.Clamp(finalPower, 0, fullWidth); //starts increasing power when the power reaches 0 if (finalPower == 0) { powerInc = true; powerDec = false; } powerBar.UpdatePower(finalPower, fullWidth); } ////////////////////////////////////For right clicking///////////////////////////// if (Input.GetMouseButtonDown(1) && leftClick != 0) { leftClick--; powerInc = false; powerDec = false; finalPower = 0; } this.stopShip(); }//update bracket
void Start() { currentShip = FindObjectOfType <ShipPhysics> (); StartGame(); galaxyText.text = "Galaxy " + galaxy; }