private void circleDamage() { if (DamageCircle.IsOutsideCircle_Static(GameObject.Find("Player").transform.position)) { currentHealth -= 10; healthBar.SetHealth(currentHealth); if (facing == 1.0f) { if (currentHealth <= 0) { animator.SetBool("Dead_R", true); player_dead = true; } else { animator.SetTrigger("Hurt_R"); } } else if (facing == -1.0f) { if (currentHealth <= 0) { animator.SetBool("Dead_L", true); player_dead = true; } else { animator.SetTrigger("Hurt_L"); } } } }
// Update is called once per frame void Update() { if (DamageCircle.IsOutSideCircle(gameObject.transform.position) && carrier == null) { gameObject.SetActive(false); unityEvent.Invoke(); } }
private void SpawnDamageCircle() { DamageCircle newCircle = Instantiate(DamageCirclePrefab, transform.position, Quaternion.identity); newCircle.transform.localScale = transform.localScale; newCircle.SetDamage(_damage); SpawnBulletShadow(_tank.transform.position, transform.position, transform.localScale); }
// Player only // -1 for missDistance is used to indicate a random missDistance & random missAngle. public override void fire(PlayerInput pI, float missDistance, float missAngle, int isThisShotgun, int shotIndex, out Combat playerHit, out float playerDamageDone) { float dmg = DamageCircle.touchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle, damageDealt, 0.25f); missDistance /= (1 + 1f * DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle)); // Doubles accuracy for damage circle. Vector3 fireFromPos; if (parentPlayerMove.thisIsMine && !parentPlayerMove.GetComponent <ClassControl> ().isBot) { // Adjust so it comes out of the viewmodel gun: fireFromPos = parentPlayerMove.mainCamera.transform.position + (parentPlayerMove.mainCamera.transform.rotation * Quaternion.Inverse(parentPlayerMove.playerView.viewmodelCamera.transform.rotation)) * (viewmodelUnlockObject.transform.position - parentPlayerMove.playerView.viewmodelCamera.transform.position); } else { fireFromPos = unlockObject.transform.position; } // Modify firePos here if guns are off with method override. // Hang on! if (OperationNetwork.isServer && isThisShotgun == 0) { GameManager.rewindStatesToTick(pI.tickNumber); } Vector3[] posToSend = HitscanGun.hitscanShoot(parentPlayerMove.mainCamera.transform.position, fireFromPos, miss(parentPlayerMove.mainCamera.transform.rotation, parentPlayerMove.mainCamera.transform.forward, missDistance, missAngle), unlockObject, parentPlayerMove.GetComponent <PlayerAnimation>(), soundEffect, getBulletType(), parentPlayerMove.GetComponent <Combat>().team, dmg, 0.5f, 5 - (int)(3 * DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle)), 200, isThisShotgun, this, out playerHit, out playerDamageDone, parentPlayerMove.plyr); // Special case, PISTOL! if (this is Pistol) { ((Pistol)this).attemptConductiveExplode(posToSend [posToSend.Length - 1]); } // Hang on! if (OperationNetwork.isServer && isThisShotgun == 0) { GameManager.revertColliderStates(); } // The hitscan bullets need to be sent to the clients if (OperationNetwork.isServer) { Vector3[] sendPos = new Vector3[posToSend.Length - 1]; Array.Copy(posToSend, 1, sendPos, 0, sendPos.Length); parentPlayerMove.GetComponent <SyncPlayer> ().currentTriggerSet.trigger(SyncPlayer.HITSCAN, sendPos); } }
private void Awake() { instance = this; circleShrinkSpeed = 20f; circleTransform = transform.Find("circle"); topTransform = transform.Find("top"); bottomTransform = transform.Find("bottom"); leftTransform = transform.Find("left"); rightTransform = transform.Find("right"); SetCircleSize(new Vector3(0, 0), new Vector3(200, 200)); SetTargetCircle(new Vector3(0, 0), new Vector3(160, 160), 5f); }
private void Awake() { instance = this; circleShrinkSpeed = 5f; circleTransform = transform.Find("circle"); topTransform = transform.Find("top"); bottomTransform = transform.Find("bottom"); leftTransform = transform.Find("left"); rightTransform = transform.Find("right"); SetCircleSize(new Vector3(0, 0), new Vector3(initialCircleSize, initialCircleSize)); SetTargetCircle(new Vector3(0, 0), new Vector3(initialTargetCircleSize, initialTargetCircleSize), 60f); }
// Update is called once per frame void Update() { accumulatedTime += Time.deltaTime; HealthController hc = GetComponent <HealthController>(); if (DamageCircle.IsOutSideCircle(transform.position) || isOnFire) { fire.SetActive(true); if (accumulatedTime > damageInterval) { accumulatedTime = 0; hc.Damage(10); } } else { fire.SetActive(false); } }
// Start is called before the first frame update void Start() { RescureSpotRadius = 10f; instance = this; circleTransform = transform.Find("Circle"); CirclePosition = circleTransform.position; SetCircle(new Vector3(0, 0), new Vector3(300f, 300f)); DISTANCE_TEST = .5f; FIRES_AMOUNT = 200; GenerateFires(); shrinkTimer = DEFAULT_SHRINK_TIMER; SetTargetCircle(new Vector3(0f, 0f), new Vector3(300f * 0.8f, 300f * 0.8f)); }
public virtual float GetSpeed() { return(25f * (1f + DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle) * 1f)); // Was 20f }
void swingDamage(PlayerInput pI) { if (targetHit) { return; } // Hang on! if (OperationNetwork.isServer) { GameManager.rewindStatesToTick(pI.tickNumber); } // To predict stuff like blood effects: float damage = getDamage(); damage = DamageCircle.touchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle, damage, 0.5f); // Currently, meelee does not collide with walls & stuff. (Nor allied players) Collider[] hitObjects = Physics.OverlapBox(parentPlayerMove.mainCamera.transform.position + parentPlayerMove.mainCamera.transform.forward * 1.3f, new Vector3(0.6f, 0.5f, 1.9f), parentPlayerMove.mainCamera.transform.rotation, 1 << (22 - 14 * parentPlayerMove.GetComponent <Combat>().team) | 1 << (15 - 5 * parentPlayerMove.GetComponent <Combat>().team)); // For now, hit everything, possibly an interesting mechanic. // Find the closest one, and hit that one. It also needs to be closest to the center? float bestDistance = 1.0f; // Max Range. (Kind of redundant, but it's used to round off the edges) Collider bestHit = null; foreach (Collider hit in hitObjects) { float dist = Vector3.Distance(parentPlayerMove.mainCamera.transform.position, hit.ClosestPointOnBounds(parentPlayerMove.mainCamera.transform.position)); if (dist >= bestDistance) { continue; } if (hit.gameObject.layer == 22 - 14 * parentPlayerMove.GetComponent <Combat>().team) { if (hit is UnityEngine.CapsuleCollider && hit.gameObject.GetComponent <Combat>().team != parentPlayerMove.GetComponent <Combat>().team) { bestDistance = dist; bestHit = hit; } } else if (PlayerMade.IsEnemy(hit.transform, parentPlayerMove.GetComponent <Combat>().team)) { bestDistance = dist; bestHit = hit; } } // It's a copy and paste of the code above as far as if statements go: if (bestHit != null) { targetHit = true; if (bestHit.gameObject.layer == 22 - 14 * parentPlayerMove.GetComponent <Combat>().team) { if (bestHit is UnityEngine.CapsuleCollider && bestHit.gameObject.GetComponent <Combat>().team != parentPlayerMove.GetComponent <Combat>().team) { bestHit.gameObject.GetComponent <Combat>().TakeDamage(damage, 0.75f, parentPlayerMove.mainCamera.transform.forward, false, Combat.MEELEE, true, parentPlayerMove.transform.position, parentPlayerMove.plyr); // isHitscan because it's determined playerSide. (dmg shouldn't be done if dead) } } else if (PlayerMade.IsEnemy(bestHit.transform, parentPlayerMove.GetComponent <Combat>().team)) { PlayerMade.TakeDamageObjectG(bestHit.transform, damage, parentPlayerMove.transform.position, true, parentPlayerMove.plyr); } } // Hang on! if (OperationNetwork.isServer) { GameManager.revertColliderStates(); } }
void HudUpdate() { GameManager.UpdateKillFeed(); HealthBarUpdate(); UpdateTrapSelectionZoneMenu(); for (int i = 0; i < trapsHud.Length; i++) { trapsHud [i].SetActive(isTrapSelectionMenuOpen); } respawnHud.transform.parent.gameObject.SetActive(Player.thisPlayer != null && Player.thisPlayer.playerObject == null); if (Player.thisPlayer != null && Player.thisPlayer.playerObject == null) { respawnHud.fillAmount = Mathf.Clamp01(1 - Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer()); respawnHud.transform.parent.GetComponent <Image>().fillAmount = Mathf.Clamp01(Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer()); int respawnTimer = (int)(Player.thisPlayer.getRespawnTimer() + 1); if (respawnTimer == 1) { respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in 1 second."; } else { respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in " + respawnTimer + " seconds."; } } // Class Selection Hud gets priority if (Player.thisPlayer && Player.thisPlayer.team == 1 && !OptionsMenu.classSelectionMenuOpen) { bool needTrap = false; for (int i = 0; i < Player.thisPlayer.trapTypes.Length; i++) { if (Player.thisPlayer.trapTypes [i] == 255) { needTrap = true; } } if (needTrap && !PlayerHud.isTrapSelectionMenuOpen) { PlayerHud.isTrapSelectionMenuOpen = true; OptionsMenu.ChangeLockState(); } else if (!needTrap && PlayerHud.isTrapSelectionMenuOpen) { PlayerHud.isTrapSelectionMenuOpen = false; OptionsMenu.ChangeLockState(); } } if (Player.thisPlayer && PlayerHud.isTrapSelectionMenuOpen) { for (int x = 0; x < trapsChoices.GetLength(0); x++) { for (int y = 0; y < trapsChoices.GetLength(1); y++) { trapsChoices [x, y].transform.Find("Text").GetComponent <Text> ().text = BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[Player.thisPlayer.myRandomTrapChoices[x * trapsChoices.GetLength(1) + y]]]; trapsChoices [x, y].GetComponent <BuyNewTrap> ().buyId = Player.thisPlayer.myRandomTrapChoices [x * trapsChoices.GetLength(1) + y]; trapsChoices [x, y].GetComponent <BuyNewTrap> ().rowID = (byte)x; } } } // This is how HUD should work for all unlocks: if (Player.thisPlayer) { for (int i = 0; i < displayTraps.Length; i++) { byte actual = Player.thisPlayer.trapTypes [i]; if (Player.thisPlayer.team != 1) { actual = 255; } if (displayTraps [i] != actual) { displayTraps [i] = actual; if (displayTraps [i] == 255 || Player.thisPlayer.team != 1) { trapPlayerHudTypes [i].SetActive(false); } else { trapPlayerHudTypes [i].SetActive(true); trapPlayerHudTypes [i].transform.Find("Text").GetComponent <Text> ().text = "(" + OptionsMenu.getBindString(OptionsMenu.binds [OptionsMenu.TRAP_1 + i]) + ") " + BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[displayTraps [i]]]; } } if (displayTraps[i] != 255 && Player.thisPlayer.playerObject) { int trapTypeIndex = BuyNewTrap.trapIndecies[Player.thisPlayer.trapTypes [i]]; PlacePlayerMade.setCharge(trapPlayerHudTypes [i], Mathf.Clamp01((Player.thisPlayer.playerObject.GetComponent <SyncPlayer>().playerTime - Player.thisPlayer.trapCoolDownsStartedAt [i]) / (float)(BuyNewTrap.baseTrapCosts [trapTypeIndex] * BuyNewTrap.maxTrapsLoaded[trapTypeIndex] * Time.fixedDeltaTime)), 1f / BuyNewTrap.maxTrapsLoaded[trapTypeIndex]); } } } if (OperationNetwork.connected) { if (Time.time - lastNetworkSettingsRead > 1) { if (OperationNetwork.isServer) { dataSentPerSecond = OperationNetwork.getClient(32767).dataSent / (Time.time - lastNetworkSettingsRead); OperationNetwork.getClient(32767).dataSent = 0; networkSettings.GetComponent <Text> ().text = (int)(dataSentPerSecond / 100) / 10.0f + " KB/s"; } else { dataSentPerSecond = RunGame.myClient.dataOutRate / (Time.time - lastNetworkSettingsRead); RunGame.myClient.dataOutRate = 0; float dataRecievedPerSecond = RunGame.myClient.dataInRate / (Time.time - lastNetworkSettingsRead); RunGame.myClient.dataInRate = 0; networkSettings.GetComponent <Text> ().text = "Sent: " + (int)(dataSentPerSecond / 100) / 10.0f + " KB/s Recieved: " + (int)(dataRecievedPerSecond / 100) / 10.0f + " KB/s"; } lastNetworkSettingsRead = Time.time; } } if (OperationNetwork.connected && Player.thisPlayer != null && Player.thisPlayer.playerObject != null) { PlayerMove pMove = Player.thisPlayer.playerObject.GetComponent <PlayerMove> (); float touchPercent = DamageCircle.isTouchingDamageCircle(pMove.timeSinceTouchingDamageCircle); if (touchPercent > 0) { buffHud.transform.parent.GetComponent <Image> ().enabled = true; buffHud.enabled = true; buffHud.fillAmount = touchPercent; } else { // Disable the rendering of it: buffHud.transform.parent.GetComponent <Image> ().enabled = false; buffHud.enabled = false; } healthHud.enabled = true; healthHud.transform.parent.GetComponent <Image> ().enabled = true; healthHudText.enabled = true; healthHud.transform.parent.GetComponent <Image> ().fillAmount = 1 - pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth; healthHud.fillAmount = pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth; healthHudText.text = (short)pMove.GetComponent <Combat> ().health + " HP"; if (Player.thisPlayer.playerObject != playerObjectHudLoaded) { playerObjectHudLoaded = Player.thisPlayer.playerObject; float origNum = getHudHeightUsed(classHud.transform); // Unload old hud: foreach (Transform t in classHud.transform) { if (t.name != "AdjacentClassHud") { Destroy(t.gameObject); } } foreach (Transform t in classHud.transform.Find("AdjacentClassHud")) { Destroy(t.gameObject); } // Create new hud: foreach (Unlock unlock in Player.thisPlayer.playerObject.GetComponent <ClassControl>().getUnlocks()) { if (unlock != null) { unlock.setHudElement(classHud.transform, origNum); } } int classLoaded = Player.thisPlayer.playerObject.GetComponent <ClassControl> ().classNum; // Phase through & Speed Boost are not unlocks, despite having some similar qualities: (Like the HUD) if (classLoaded == 0) { Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Cooldown", "Phase Shift", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum); Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement2 = Unlock.setHudElement(classHud.transform, "Armor", "Armor", OptionsMenu.MAIN_ABILITY, null, origNum); } else if (classLoaded == 3) { Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Cooldown", "Speed Boost", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum); } else if (classLoaded == 4) { if (OptionsMenu.hudPanels.ContainsKey("Healthtaken")) { Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Healthtaken", "Health Taken", OptionsMenu.ULTIMATE_ABILITY, null, origNum); } } // The updating for the HUD is handled within the unlocks / class itself } } else { // Hide hud completely: buffHud.transform.parent.GetComponent <Image> ().enabled = false; buffHud.enabled = false; healthHud.enabled = false; healthHud.transform.parent.GetComponent <Image> ().enabled = false; healthHudText.enabled = false; } // SCOREBOARD: if (Input.GetKey(KeyCode.Tab)) { scoreBoard.SetActive(true); for (byte team = 0; team < 2; team++) { List <Player> players = GameManager.getPlayersOnTeam(team); for (int i = 0; i < scoreBoardPlayers[team].Count; i++) { if (i < players.Count) { scoreBoardPlayers [team] [i].SetActive(true); scoreBoardPlayers [team] [i].transform.Find("Text").GetComponent <Text> ().text = players [i].playerName; Color c = scoreBoardPlayers [team] [i].GetComponent <Image> ().color; if (players [i].playerObject != null) { scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 1f); } else { scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 0.2f); } scoreBoardKills [team] [i].text = "" + players[i].kills; scoreBoardDeaths [team] [i].text = "" + players[i].deaths; } else { scoreBoardPlayers [team] [i].SetActive(false); scoreBoardKills [team] [i].text = ""; scoreBoardDeaths [team] [i].text = ""; } } } } else { scoreBoard.SetActive(false); } // Display kill feed: for (int i = 0; i < killFeed.Count; i++) { if (GameManager.recentPlayerKillers.Count > i) { killFeed [i].parent.gameObject.SetActive(true); string killDisplay = ""; if (GameManager.PlayerExists(GameManager.recentPlayerKillers [i])) { killDisplay = GameManager.GetPlayer(GameManager.recentPlayerKillers [i]).playerName + " killed "; } if (GameManager.PlayerExists(GameManager.recentPlayerDeaths [i])) { killFeed [i].GetComponent <Text> ().text = killDisplay + GameManager.GetPlayer(GameManager.recentPlayerDeaths [i]).playerName; } } else { killFeed [i].parent.gameObject.SetActive(false); } } // Class Selection Menu: if (OptionsMenu.classSelectionMenuOpen && Player.thisPlayer != null) { classSelectionMenu.SetActive(true); Color color; if (Player.thisPlayer.team == 0) { color = new Color(0, 0, 1f, 0.5f); } else if (Player.thisPlayer.team == 1) { color = new Color(1f, 0, 0, 0.5f); } else { color = new Color(1f, 1f, 1f, 0.5f); } classSelectionMenu.GetComponent <Image> ().color = color; for (byte i = 0; i < classSelectionTeams.Length; i++) { if (Player.thisPlayer.team == i) { classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 1f); } else { classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 0.6f); } } for (byte i = 0; i < classTypes.Count; i++) { if (Player.thisPlayer.team == 0) { classTypes [i].gameObject.SetActive(true); if (Player.thisPlayer.classNum == i) { classTypes [i].color = new Color(0.2f, 0.2f, 1f, 1f); } else { classTypes [i].color = new Color(0.7f, 0.7f, 1f, 0.8f); } } else if (Player.thisPlayer.team == 1) { classTypes [i].gameObject.SetActive(true); if (Player.thisPlayer.classNum == i) { classTypes [i].color = new Color(1f, 0.2f, 0.2f, 1f); } else { classTypes [i].color = new Color(1f, 0.7f, 0.7f, 0.8f); } } else { classTypes [i].gameObject.SetActive(false); } } } else { classSelectionMenu.SetActive(false); } }
// Use this for initialization private void Start() { character = new Character(); character.SetEquippedBodyArmor(Character.BodyArmor.Tier_2); characterWindow.SetCharacter(character); FunctionPeriodic.Create(() => { if (DamageCircle.IsOutsideCircle_Static(GetPosition())) { character.Damage(4); } }, .1f); V_Object vObject = CreateBasicUnit(transform, new Vector3(500, 680), 30f, GameAssets.i.m_MarineSpriteSheet); V_UnitAnimation unitAnimation = vObject.GetLogic <V_UnitAnimation>(); V_UnitSkeleton unitSkeleton = vObject.GetLogic <V_UnitSkeleton>(); V_IObjectTransform objectTransform = vObject.GetLogic <V_IObjectTransform>(); bool canShoot = true; V_UnitSkeleton_Composite_Weapon unitSkeletonCompositeWeapon = new V_UnitSkeleton_Composite_Weapon(vObject, unitSkeleton, GameAssets.UnitAnimEnum.dMarine_AimWeaponRight, GameAssets.UnitAnimEnum.dMarine_AimWeaponRightInvertV, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRight, GameAssets.UnitAnimEnum.dMarine_ShootWeaponRightInvertV); vObject.AddRelatedObject(unitSkeletonCompositeWeapon); unitSkeletonCompositeWeapon.SetActive(); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_BodyHead = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "Body", "Head" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_BodyHead); V_UnitSkeleton_Composite_Walker unitSkeletonCompositeWalker_Feet = new V_UnitSkeleton_Composite_Walker(vObject, unitSkeleton, GameAssets.UnitAnimTypeEnum.dMarine_Walk, GameAssets.UnitAnimTypeEnum.dMarine_Idle, new[] { "FootL", "FootR" }); vObject.AddRelatedObject(unitSkeletonCompositeWalker_Feet); FunctionUpdater.Create(() => { Vector3 targetPosition = UtilsClass.GetMouseWorldPosition(); Vector3 aimDir = (targetPosition - vObject.GetPosition()).normalized; // Check for hits Vector3 gunEndPointPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash"); RaycastHit2D raycastHit = Physics2D.Raycast(gunEndPointPosition, (targetPosition - gunEndPointPosition).normalized, Vector3.Distance(gunEndPointPosition, targetPosition)); if (raycastHit.collider != null) { // Hit something targetPosition = raycastHit.point; } unitSkeletonCompositeWeapon.SetAimTarget(targetPosition); if (canShoot && Input.GetMouseButton(0)) { // Shoot canShoot = false; // Replace Body and Head with Attack unitSkeleton.ReplaceBodyPartSkeletonAnim(GameAssets.UnitAnimTypeEnum.dMarine_Attack.GetUnitAnim(aimDir), "Body", "Head"); // Shoot Composite Skeleton unitSkeletonCompositeWeapon.Shoot(targetPosition, () => { canShoot = true; }); // Add Effects Vector3 shootFlashPosition = vObject.GetLogic <V_UnitSkeleton>().GetBodyPartPosition("MuzzleFlash"); if (OnShoot != null) { OnShoot(this, new OnShootEventArgs { gunEndPointPosition = shootFlashPosition, shootPosition = targetPosition }); } //Shoot_Flash.AddFlash(shootFlashPosition); //WeaponTracer.Create(shootFlashPosition, targetPosition); } // Manual Movement bool isMoving = false; Vector3 moveDir = new Vector3(0, 0); if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { moveDir.y = +1; isMoving = true; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { moveDir.y = -1; isMoving = true; } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { moveDir.x = -1; isMoving = true; } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { moveDir.x = +1; isMoving = true; } moveDir.Normalize(); float moveSpeed = 50f; Vector3 targetMoveToPosition = objectTransform.GetPosition() + moveDir * moveSpeed * Time.deltaTime; // Test if can move there raycastHit = Physics2D.Raycast(GetPosition() + moveDir * .1f, moveDir, Vector3.Distance(GetPosition(), targetMoveToPosition)); if (raycastHit.collider != null) { // Hit something } else { // Can move, no wall objectTransform.SetPosition(targetMoveToPosition); } if (isMoving) { Dirt_Handler.SpawnInterval(GetPosition() + new Vector3(0, -4f), moveDir * -1f); } // Update Feet unitSkeletonCompositeWalker_Feet.UpdateBodyParts(isMoving, moveDir); if (canShoot) { // Update Head and Body parts only when Not Shooting unitSkeletonCompositeWalker_BodyHead.UpdateBodyParts(isMoving, aimDir); } }); }
void areaChecks(PlayerInput pI) { Vector3 halfHeight = new Vector3(0, GetComponent <CharacterController>().height / 2 * transform.localScale.x, 0); Vector3 center = transform.position + GetComponent <CharacterController>().center; Vector3 oldCenter = lastPlayerPosition + GetComponent <CharacterController>().center; Collider[] colliders = Physics.OverlapBox(center, halfHeight + new Vector3(GetComponent <CharacterController>().radius *transform.localScale.x, 0, GetComponent <CharacterController>().radius *transform.localScale.x), Quaternion.identity, 1 << 9 | 1 << 24 - GetComponent <Combat>().team); // All so it includes where the collider started at. Health packs should probably be picked up like this, but we'll see timeSinceTouchingDamageCircle += pI.frameTime; isInSpawnRoom = false; isInTrapSelectionZone = false; // Dirt mound / Force field hit detection: (And spawn room detection) bool collided = false; for (int i = 0; i < colliders.Length; i++) { if (colliders [i].gameObject.GetComponent <HoverMoundCollision> ()) { hoverMoundCollision(pI, colliders[i]); collided = true; // NOT EFFECTED BY enemy team's damage circles: (Thus, it is impossible to get through them w/o phase shift, icicle jump, rocket jump, speed boost.) } else if ((colliders [i].gameObject.CompareTag("DamageBoxBlue") && GetComponent <Combat> ().team == 0) || (colliders [i].gameObject.CompareTag("DamageBoxRed") && GetComponent <Combat> ().team == 1)) { if (DamageCircle.isTouchingDamageCircle(timeSinceTouchingDamageCircle) == 0) { timeSinceTouchingDamageCircle = Mathf.Max(0, 1.5f - pI.frameTime * 2); } else { timeSinceTouchingDamageCircle = Mathf.Max(timeSinceTouchingDamageCircle - pI.frameTime * 2); } } else if (colliders [i].gameObject.layer == 24 - GetComponent <Combat> ().team&& colliders [i].isTrigger && colliders [i].transform.parent.gameObject.layer != 14) // Might as well check if isTrigger. Checks opposite team notabely. { isInSpawnRoom = true; } else if (colliders [i].gameObject.CompareTag("SelectTrapZone") && GetComponent <Combat> ().team == 1) { isInTrapSelectionZone = true; } } if (OperationNetwork.isServer) { RaycastHit[] raycastHit = Physics.CapsuleCastAll(oldCenter - halfHeight, oldCenter + halfHeight, GetComponent <CharacterController>().radius *transform.localScale.x, Vector3.Normalize(center - oldCenter), Vector3.Distance(center, oldCenter), 1 << 9 | 1 << 24 - GetComponent <Combat>().team | 1 << 21 - GetComponent <Combat>().team); foreach (RaycastHit rch in raycastHit) { if (rch.collider.gameObject.CompareTag("RocketBullet")) { if (rch.collider.gameObject.GetComponent <Bullet> ().exists) { rch.collider.gameObject.GetComponent <Bullet> ().BlowUp(transform); // This works because directHit accounts for it, despite the fact that technically this parent object isn't part of the hitbox. } } } } // Dirt mound history: if (collided) { inDirtMound += pI.frameTime; } else { inDirtMound = 0; } }