private void OnCollisionEnter(Collision collision) { GameObject other = collision.gameObject; ShipControl otherShip = other.GetComponent <ShipControl>(); // Handle ramming with enemy ship if (otherShip != null) { // Compute the average dot product between the contact normals and the forward direction // The closer it is to -1 (i.e. average normal and forward are opposite), the more directly we are going // into the collision, and the more damage we will deal to them float avgDot = 0; for (int i = 0; i < collision.contactCount; i++) { avgDot += Vector3.Dot(collision.GetContact(i).normal, transform.forward); } avgDot /= Mathf.Max(1, collision.contactCount); // The closer we are to -1, the less damage we deal to this ship float damageToThisShip = Mathf.Abs(-1 - avgDot); // Square the damage then scale it by the velocity of the collision damageToThisShip *= damageToThisShip; damageToThisShip *= collision.relativeVelocity.magnitude * 2f; // Deal the damage to this ship GetComponent <ShipHealth>().Health -= Mathf.CeilToInt(damageToThisShip); } }
public void ChangeShips() { int m = ShipContainer.GetSpaceshipCount(); for (int i = 0; i < shipControls.Length; i++) { if (shipControls [i]) { GameObject ship = ShipContainer.GetSpaceShip(i); ShipControl sc = null; int image = 0; if (ship) { ship.transform.position = resetPositions [i]; ship.transform.rotation = Quaternion.identity; sc = ship.GetComponent <ShipControl> (); image = (int)sc.shipType; sc.Reset(); } shipControls [i].SetShip(sc, shipImages [image], i <= m); } } if (scrapText) { scrapText.text = Mathf.FloorToInt(Highscore.GetScore()).ToString(); } }
private void FixedUpdate() { if (SceneGlobals.Paused) { goto PAUSEDRUNNTIME; } //Get the steering if (control_script == null) { control_script = GetComponent <ShipControl>(); } Vector3 transl_inp; Vector3 rot_inp; transl_inp = control_script.inp_thrust_vec; rot_inp = control_script.inp_torque_vec; bool firing = false; foreach (ParticleSystem ps in trans_Up.Keys) { //Calculate the actual intnsity of the given rcs port Vector3 transl_power = new Vector3(trans_Star[ps], trans_Up[ps], trans_Fore[ps]) * -1; Vector3 rot_power = new Vector3(rot_pitch[ps], rot_yaw[ps], rot_roll[ps]); float power = Mathf.Min(Mathf.Max(Vector3.Dot(transl_inp.normalized, transl_power) + Vector3.Dot(rot_inp.normalized, rot_power), -1.0f), 1.0f); //Start or stop the effect based on the intensity if (power > 0.3f) { if (!ps.isPlaying) { ps.Play(); sound_timer = 0; } if (sound_timer >= .5f) { sound_timer = 0; } firing = true; } else { if (ps.isPlaying) { ps.Stop(); } } } if (control_script.myship.IsPlayer) { if (firing) { Globals.audio.RCSPlay(); } else { Globals.audio.RCSStop(); } } PAUSEDRUNNTIME :; }
void Start() { instance = this; Time.timeScale = 0; // Setup targets targets.Setup(this); // Setup stats currentHealth = maxHealth; drillCurrent = drillMax; timeLastDrilled = -1; timeCollisionStarted = -1f; timeInvincible = -1f; // Setup UI lifeBar.wholeNumbers = true; lifeBar.minValue = 0; lifeBar.maxValue = maxHealth; lifeBar.value = currentHealth; drillBar.wholeNumbers = false; drillBar.minValue = 0; drillBar.maxValue = drillMax; drillBar.value = currentHealth; flightModeLabel.text = FlightTowardsTarget; dangerHealth.enabled = false; emptyDrill.enabled = false; ramParticles.Stop(); }
private void resetTransform() { this.attachedPlayer.transform.position = this.gameObject.transform.position; if (!GlobalSettings.SinglePlayer) { GameObject mothership = null; if (this.attachedPlayer.gameObject.layer == (int)Layers.Team1Actor) { mothership = GameObject.Find(GlobalSettings.Team2MothershipName); } else if (this.attachedPlayer.gameObject.layer == (int)Layers.Team2Actor) { mothership = GameObject.Find(GlobalSettings.Team1MothershipName); } else { throw new Exception("Attached player ship of spawn point has invalid layer!"); } this.attachedPlayer.transform.LookAt(mothership.transform); } ObjectTransformer transformer = this.attachedPlayer.GetComponent <ObjectTransformer>(); transformer.Translation = Vector3.zero; ShipControl shipControl = this.attachedPlayer.GetComponent <ShipControl>(); shipControl.CurrentSpeed = 0; }
public void play(ShipControl control) { //Debug.Log(direction); if (control.AxisValue > 0) { foreach (Material finMaterial in posFinMaterials) { animateMaterialTransparent(finMaterial); } } else { foreach (Material finMaterial in posFinMaterials) { stopMaterialTransparent(finMaterial); } } if (control.AxisValue < 0) { foreach (Material finMaterial in negFinMaterials) { animateMaterialTransparent(finMaterial); } } else { foreach (Material finMaterial in negFinMaterials) { stopMaterialTransparent(finMaterial); } } }
private bool CanLockOn(ShipControl ship, Asteroid_Control asteroid) { Vector3 spaceship_to_asteriod = asteroid.transform.position - ship.transform.position; return(((Vector3.Dot(ship.transform.forward, spaceship_to_asteriod) / (spaceship_to_asteriod.magnitude)) > 0.8f) && (Vector3.Distance(ship.transform.position, asteroid.transform.position) < MAX_LOC_ON_DISTANCE)); }
public void Start() { // For the template object if (parent == null) { return; } _camera = SceneGlobals.ship_camera; button = GetComponent <Button>(); img = GetComponent <Image>(); player = SceneGlobals.Player; player_control = player.Object.GetComponent <ShipControl>(); parent_tgt = parent.Associated; predicted_point = Instantiate(GameObject.Find("pred_point")).GetComponent <Image>(); predicted_point.transform.SetParent(transform); pred_point_velocity = predicted_point.GetComponentsInChildren <Text>() [0]; pred_point_distance = predicted_point.GetComponentsInChildren <Text>() [1]; var clicked_color = parent_tgt.Friendly ? new Color(.25f, .25f, .92f) : new Color(.92f, .92f, .25f); predicted_point.color = pred_point_velocity.color = pred_point_distance.color = clicked_color; Deactivate(); started = true; }
public override void Upgrade(GameObject ship) { Destroy(ship.GetComponent <BaseShield>()); ShipControl sc = ship.GetComponent <ShipControl>(); sc.shield = ship.AddComponent <ReflectShield>(); }
public void SetShip(ShipControl ship, Sprite image, bool setActive, Sprite active, Sprite inActive) { this.gameObject.SetActive(setActive); affectedShip = ship; display.sprite = image; activeSprite = active; inActiveSprite = inActive; }
private void Start() { script = SceneGlobals.ui_script; add_menu = script.add_group_menu; player_control = SceneGlobals.Player.Object.GetComponent <ShipControl>(); arrow_size_slider = GameObject.Find("arrow_size").GetComponent <Slider>(); }
private void Awake() { player = GameObject.FindGameObjectWithTag("Player"); playerCollider = GameObject.FindGameObjectWithTag("Player").GetComponent <BoxCollider2D>(); shipControl = GameObject.FindGameObjectWithTag("Player").GetComponent <ShipControl>(); playerPivot = GameObject.FindGameObjectWithTag("Player").transform.FindChild("Pivot").gameObject; fireOrb = GameObject.FindGameObjectWithTag("Player").transform.FindChild("Pivot").transform.FindChild("Sphere").gameObject; dropStuff = GameObject.Find("PowerUps").GetComponent <DropStuff>(); }
//override base powerup, add half damage shield public override void Upgrade(GameObject ship) { print("Upgrade: Half Damage"); ShipControl sc = ship.GetComponent <ShipControl>(); Destroy(sc.shield); sc.shield = ship.AddComponent <HalfDamageShield>(); }
void Start() { control = transform.parent.GetComponent <ShipControl>(); stats = PlayerStats.instance; if (stats != null) { maxSpeed = stats.maxSpeed; } }
//override base upgrade, replace base shot w/ Triple shot public override void Upgrade(GameObject ship) { print("Upgrade: Triple Attack"); ShipControl sc = ship.GetComponent <ShipControl>(); //get ship controllers Destroy(sc.attack); //remove base attack sc.attack = ship.AddComponent <TripleShot>(); //add triple shot }
void Start() { m_Body = GetComponent <Rigidbody2D>(); ship = GameObject.Find("Ship").GetComponent <ShipControl>(); HUD = GameObject.Find("HUD").GetComponent <Canvas>().GetComponent <HUDUpdate>(); StartCoroutine(Shoot()); EnMan = GameObject.Find("HUD").GetComponent <EnemyManager>(); m_ExplSFX = GameObject.Find("EnemyKills").GetComponent <AudioSource>(); }
public virtual void Awake() { if (FOV == 0) { FOV = 60f; } if (FOVForFire == 0) { FOVForFire = 10f; } if (SearchGradesOnAlert == 0) { SearchGradesOnAlert = 30f; } if (minHealthToRecharge == 0) { minHealthToRecharge = 15f; } entity = GetComponent <Entity>(); health = GetComponent <Health>(); shipControlComponent = GetComponent <ShipControl>(); emInputComponent = GetComponent <EMInput>(); navAgent = gameObject.GetComponent <NavMeshAgent>(); if (triggerPerception == null) { triggerPerception = GetComponent <SphereCollider>(); if (triggerPerception == null) { triggerPerception = GetComponentInChildren <SphereCollider>(); } } storageStoppingDistance = navAgent.stoppingDistance; triggerPerception.isTrigger = true; triggerPerception.radius = perceptionRadius; entity.ImpactReceive += entity_ImpactReceive; patrolWayPoints = new List <GameObject>(); foreach (Transform child in sector.transform) { patrolWayPoints.Add(child.gameObject); } if (behavior == Behavior.Patrol) { state = States.Patrol; } enemyPreviousSighting = resetPosition; personalLastSighting = resetPosition; }
public void InitPlayer(string path) { GameObject temp = Resources.Load <GameObject>(path); Vector3 rotate = new Vector3(0.0f, 90f, -90f); Vector3 pos = new Vector3(-220, 0.0f, 260f); player = GameObject.Instantiate(temp, pos, Quaternion.Euler(rotate), gameObject.transform); m_ShipControl = player.AddComponent <ShipControl>(); player.AddComponent <BulletShotHelper>(); }
private PlayerControls() { power = new ShipControl("Power"); horizontal = new ShipControl("Horizontal"); vertical = new ShipControl("Vertical"); horizStrafe = new ShipControl("HorizStrafe"); verticStrafe = new ShipControl("VerticStrafe"); roll = new ShipControl("Roll"); combat = new ShipControl("Combat"); }
void AddBoost() { /// ShipControl _shipControl = ship.GetComponent <ShipControl>(); if (_shipControl != null) { _shipControl.AddBoost(); } }
private void Start() { LaserPosition = new Vector2(0f, 0.5f); Stats = GameObject.Find("spaceship").GetComponent <statystyki>(); Countdown = GameObject.Find("Main Camera").GetComponent <SetCountdown>(); ShipControl = GameObject.Find("spaceship").GetComponent <ShipControl>(); Skins = GameObject.Find("spaceship").GetComponent <Skins>(); LaserSkin = GameObject.Find("laser_life").GetComponent <SpriteRenderer>(); GravityBullet = GetComponent <Rigidbody2D>(); SetSkinLaser(); }
// Start is called before the first frame update void Start() { asteroids = new List <Asteroid_Control>(); for (int i = 0; i < number_od_asteroids; i++) { asteroids.Add(spawnNewAsteroid()); } players_ship = FindObjectOfType <ShipControl>(); }
void Start() { rect = GetComponent <RectTransform>(); gui_script = SceneGlobals.ui_script; player_script = SceneGlobals.Player.control_script; source_button = GameObject.Find("turr_slide"); mask_transform = GetComponentInChildren <RectMask2D>().transform; slider = GetComponentInChildren <Slider>(); tgt_choice = GameObject.Find("TG_selecter").GetComponent <Dropdown>(); ammo_choice = GameObject.Find("Ammo_selecter").GetComponent <Dropdown>(); name_input = GetComponentInChildren <InputField>(); }
// Use this for initialization void Start() { playerNetworkSetup = GetComponent <Player_NetworkSetup>(); playerParentScript = GetComponent <Player_Parent>(); //engineParent = transform.Find ("Engines").gameObject; variablesScript = GetComponent <variables>(); healthScript = GetComponent <Player_Health>(); shipControlScript = GetComponent <ShipControl>(); playerButtonsScript = GetComponent <Player_Buttons>(); healthScript.EventRespawn += EnablePlayer; //Subscribe to event SetRespawnButton(); }
// Use this for initialization void Start() { //try to make a dict with scripts inheriting from same base createLine = GetComponent <CreateLine> (); pointCreation = GetComponent <PointCreation> (); shipControl = GetComponent <ShipControl> (); squadronControl = GetComponent <SquadronControl> (); //shipControl.enabled = false; //createLine.Disable (); //pointCreation.Disable (); SetState("Main"); }
// Use this for initialization void Start() { //if (isLocalPlayer) { variablesScript = GetComponent <variables>(); playerBoostScript = GetComponent <Player_Boost>(); playerDeathScript = GetComponent <Player_Death>(); playerRespawnScript = GetComponent <Player_Respawn>(); playerFireScript = GetComponent <Player_Fire>(); playerHealthScript = GetComponent <Player_Health>(); playerIDScript = GetComponent <Player_ID>(); shipControlScript = GetComponent <ShipControl>(); playerEngineScript = GetComponent <Player_Engine>(); playerSpotlightScript = GetComponent <Player_Spotlight>(); playerNetworkSetup = GetComponent <Player_NetworkSetup>(); if (isLocalPlayer) { playerType = PlayerPrefs.GetString("ShipType"); //print("Setting player type to: " + playerType); if (playerType != "Large" && playerType != "Medium" && playerType != "Small") { playerType = "Medium"; } if (playerType == "Small") { Cmd_EnableSmallShip(); } else if (playerType == "Medium") { Cmd_EnableMediumShip(); } else if (playerType == "Large") { Cmd_EnableLargeShip(); } CmdTellServerMyShip(playerType); } /* * if (!isLocalPlayer) { * if (playerTypeGlobal == "Small") { * Cmd_EnableSmallShip(); * } * else if (playerTypeGlobal == "Medium") { * Cmd_EnableMediumShip(); * } * else if (playerTypeGlobal == "Large") { * Cmd_EnableLargeShip(); * } * } */ }
//Singleton init void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); return; } }
void Update() { // Update rudder if (Mathf.Abs(_rudderTilt - TargetRudderTilt) <= RudderTiltSpeed * Time.deltaTime) { _rudderTilt = TargetRudderTilt; } else { _rudderTilt += RudderTiltSpeed * Time.deltaTime * Mathf.Sign(TargetRudderTilt - _rudderTilt); } Rudder.transform.rotation = Quaternion.AngleAxis(_rudderTilt, RudderAxis.right) * _rudderInitialRotation; // Update cannons if (TargetAimPos != Vector3.zero) { foreach (CannonSettings cannonSettings in Cannons) { GameObject barrel = cannonSettings.Barrel; GameObject spawnPos = cannonSettings.SpawnPos; Quaternion initialRotation = cannonSettings.InitialRotation; Quaternion initialBaseRotation = cannonSettings.InitialBaseRotation; initialBaseRotation = Quaternion.Euler(initialBaseRotation.eulerAngles.x, 0, initialBaseRotation.eulerAngles.z); var(yaw, pitch) = ShipControl.CalculateCannonAim(spawnPos.transform.position, TargetAimPos, CannonballSpeed, CannonballGravity); // Ensure the yaw angle isn't too far to either side float relativeYaw = Util.Clamp180(yaw - transform.rotation.eulerAngles.y); float clampMin = CannonMaxFiringAngle; float clampMax = 180 - CannonMaxFiringAngle; if (cannonSettings.IsRightSide) { float oldMin = clampMin; clampMin = -clampMax; clampMax = -oldMin; } if (relativeYaw < clampMin || relativeYaw > clampMax) { // relativeYaw = Util.ClosestAngle(relativeYaw, clampMin, clampMax); continue; } float cannonYaw = relativeYaw + 90; Quaternion baseRotation = Quaternion.AngleAxis(cannonYaw, Vector3.up) * initialBaseRotation; barrel.transform.localRotation = Quaternion.AngleAxis(pitch, Vector3.right) * initialRotation; cannonSettings.Base.transform.localRotation = baseRotation; } } }
/// <summary> /// Создание нового корабля /// </summary> private void CreateNewShip() { var newShip = new SpaceShip(MapCenter, MapWidth, _speed, _level); var newShipObject = new ShipControl(newShip); Panel.SetZIndex(newShipObject, 11); Map.Children.Add(newShipObject); Canvas.SetTop(newShipObject, -1000); Canvas.SetLeft(newShipObject, -1000); _shipObjects[newShip] = newShipObject; }
public void Config(ShipControl owner, int damage, bool bounce, float lifetime, NetworkObjectPool poolToReturn) { m_Owner = owner; m_Damage = damage; m_Bounce = bounce; m_PoolToReturn = poolToReturn; if (IsServer) { // This is bad code don't use invoke. Invoke(nameof(DestroyBullet), lifetime); } }
public void Start_() { control_script = GetComponent <ShipControl>(); own_ship = control_script.myship; main_pos = own_ship.Position; navigator = new Navigation(control_script); own_ship.low_ai = this; high_level = Loader.EnsureComponent <HighLevelAI>(gameObject); own_ship.high_ai = high_level; high_level.Start_(this); high_level.enabled = HasHigherAI; }
private void LateStart() { own_ship = GetComponent <ShipControl>().myship; player_script = GameObject.FindWithTag("Player").GetComponent <ShipControl>(); player = player_script.myship; marker = Instantiate(GameObject.Find("tgt_pos_marker").GetComponent <Image>()); marker.sprite = marker_sources[0]; marker.transform.SetParent(GameObject.Find("Canvas").transform); marker.rectTransform.anchorMin = Vector2.zero; tgt_dis = GameObject.Find("tgt distance").GetComponent <Text>(); tgt_vel = GameObject.Find("tgt velocity").GetComponent <Text>(); }
public AnimationByControl(ShipControl control) { this.control = control; }