// Update is called once per frame void Update() { if (showGroundHitMarker && ManagesGame.getInstance().gameSettings.showGroundHitMarker&& !isGrounded) { ManagesGame.getInstance().utilityFunctions.particleEmission(marker.GetComponent <ParticleSystem> (), true); RaycastHit groundHit; if (Physics.Raycast(this.transform.position, -Vector3.up, out groundHit, 1000.0f)) { marker.transform.position = groundHit.point + new Vector3(0, 0.1f, 0); } } else { ManagesGame.getInstance().utilityFunctions.particleEmission(marker.GetComponent <ParticleSystem> (), false); } RaycastHit[] hits = Physics.SphereCastAll(this.transform.position + (Vector3.up * radius), radius, Vector3.down, distance + radius); foreach (RaycastHit hit in hits) { if (hit.collider.gameObject.tag != "Player" && hit.collider.gameObject.tag != "AI_Entity") { isGrounded = true; return; } } isGrounded = false; }
void Start() { marker = GameObject.FindGameObjectWithTag("positionMarker"); if (marker == null) { ManagesGame.getInstance().gameSettings.showGroundHitMarker = false; } }
public bool doBehavior(bool condition) { if (condition && !active) { if (entity == null) { entity = this.gameObject.GetComponent <AI_Entity>(); } if (entity.pushOneShotParticles != null) { entity.pushOneShotParticles.Emit(entity.pushOneShotAmount); } if (!ManagesPostProcessing.getInstance().hackingEntities.Contains(this.gameObject)) { ManagesPostProcessing.getInstance().hackingEntities.Add(this.gameObject); } if (ManagesPlayer.getInstance().playerValues.canUseAbilities) { if (entity.playRemoveAbilitiesSound) { entity.playSound(); } } ManagesPlayer.getInstance().canUseAbilities(false); ManagesGame.getInstance().utilityFunctions.particleEmission( ManagesPlayer.getInstance().noAbilityParticleSystem, true); active = true; } else if (condition && active) { if (entity.pushOneShotParticles != null) { entity.pushOneShotParticles.Emit(entity.pushOneShotAmount); } } else if (!condition && active) { ManagesPlayer.getInstance().canUseAbilities(true); if (ManagesPostProcessing.getInstance().hackingEntities.Contains(this.gameObject)) { ManagesPostProcessing.getInstance().hackingEntities.Remove(this.gameObject); } ManagesGame.getInstance().utilityFunctions.particleEmission( ManagesPlayer.getInstance().noAbilityParticleSystem, false); active = false; } return(condition); }
// Update is called once per frame void Update() { if (isPlayer) { if (ManagesPlayer.getInstance().playerPhysicsController.velocity.magnitude > 80 && !activatedParticles) { if (ManagesPlayer.getInstance().playerPhysicsController.velocity.y < -80) { actualStrength += 50; } ManagesGame.getInstance().utilityFunctions.particleEmission(ManagesPlayer.getInstance().fallingParticleSystem, true); activatedParticles = true; } else if (ManagesPlayer.getInstance().playerPhysicsController.velocity.magnitude < 80) { ManagesGame.getInstance().utilityFunctions.particleEmission(ManagesPlayer.getInstance().fallingParticleSystem, false); activatedParticles = false; } } if (!groundCheck.checkGrounded()) { if (isPlayer) { if (!ManagesPowerUps.getInstance().isPowerUpActive(PowerUpTypes.ANTI_GRAV)) { actualStrength += strengthIncrease * Time.deltaTime; } else { actualStrength = 1.0f; } } else { actualStrength += strengthIncrease * Time.deltaTime; } if (actualStrength > maximumStrength) { actualStrength = maximumStrength; } float effectiveStrength = actualStrength * this.GetComponent <Rigidbody>().mass *Time.deltaTime; myBody.AddForce(Physics.gravity * effectiveStrength, ForceMode.Impulse); } else { resetStrength(); } }
void executeBehaviors() { for (int p = 0; p < maximumPriority; p++) { for (int i = 0; i < behaviors.Length; i++) { behavior = behaviors[i]; if (behavior.type == AI_Behavior.FOLLOW_PLAYER) { AI_Controller_FollowPlayer controller = this.gameObject.GetComponent <AI_Controller_FollowPlayer>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_FollowPlayer>(); continue; } if (behavior.priority != p) { continue; } if (ManagesGame.getInstance().noHostileAI) { continue; } check = check_for_contact(behavior); controller.contact = contactRepresentation; controller.movementSpeed = behavior.movementSpeed; if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.RETURN) { AI_Controller_Return controller = this.gameObject.GetComponent <AI_Controller_Return>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_Return>(); continue; } if (behavior.priority != p) { continue; } check = check_for_contact(behavior); controller.home = home; controller.movementSpeed = behavior.movementSpeed; if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.MOVE_RANDOMLY) { AI_Controller_RandomMovement controller = this.gameObject.GetComponent <AI_Controller_RandomMovement>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_RandomMovement>(); continue; } if (behavior.priority != p) { continue; } check = check_for_contact(behavior); controller.movementSpeed = behavior.movementSpeed; if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.PUSH_PLAYER) { AI_Controller_PushPlayer controller = this.gameObject.GetComponent <AI_Controller_PushPlayer>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_PushPlayer>(); continue; } if (behavior.priority != p) { continue; } if (ManagesGame.getInstance().noHostileAI) { continue; } check = check_for_contact(behavior); controller.contact = contactRepresentation; controller.movementSpeed = behavior.movementSpeed; if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.ACTIVATE_OBJECT) { AI_Controller_ActivateGameObject controller = this.gameObject.GetComponent <AI_Controller_ActivateGameObject>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_ActivateGameObject>(); continue; } if (behavior.priority != p) { continue; } check = check_for_contact(behavior); if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.DASH) { AI_Controller_Dash controller = this.gameObject.GetComponent <AI_Controller_Dash>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_Dash>(); continue; } if (behavior.priority != p) { continue; } check = check_for_contact(behavior); if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.MULTIJUMP) { AI_Controller_Multijump controller = this.gameObject.GetComponent <AI_Controller_Multijump>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_Multijump>(); continue; } if (behavior.priority != p) { continue; } check = check_for_contact(behavior); if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.RUNAWAY) { AI_Controller_RunAway controller = this.gameObject.GetComponent <AI_Controller_RunAway>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_RunAway>(); continue; } if (behavior.priority != p) { continue; } check = check_for_contact(behavior); controller.contact = contactRepresentation; controller.movementSpeed = behavior.movementSpeed; if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.PULL) { AI_Controller_Pull controller = this.gameObject.GetComponent <AI_Controller_Pull>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_Pull>(); continue; } if (behavior.priority != p) { continue; } if (ManagesGame.getInstance().noHostileAI) { continue; } check = check_for_contact(behavior); controller.contact = contactRepresentation; controller.movementSpeed = behavior.movementSpeed; controller.distance = behavior.distance; if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } else if (behavior.type == AI_Behavior.REMOVE_ABILITIES) { AI_Controller_RemoveAbilities controller = this.gameObject.GetComponent <AI_Controller_RemoveAbilities>(); if (controller == null) { this.gameObject.AddComponent <AI_Controller_RemoveAbilities>(); continue; } if (behavior.priority != p) { continue; } if (ManagesGame.getInstance().noHostileAI) { continue; } check = check_for_contact(behavior); if (controller.doBehavior(check)) { reachedMaximumPriority = true; } } } if (reachedMaximumPriority) { p = maximumPriority; reachedMaximumPriority = false; } } }
public bool doBehavior(bool condition) { if (myBody == null) { myBody = this.gameObject.GetComponent <Rigidbody>(); } if (entity == null) { entity = this.gameObject.GetComponent <AI_Entity>(); } if (condition && !dashing && currentDashLength > entity.dashLength) { currentDashLength += entity.executionInterval; if (currentDashLength > entity.timeBetweenDashs) { currentDashLength = 0; } else { return(false); } } if (dashing) { if (entity.fallSpeedAccelerator != null) { entity.fallSpeedAccelerator.resetStrength(); } } if (condition && !dashing) { dashing = true; currentDashLength = 0; ManagesGame.getInstance().utilityFunctions.particleEmission(entity.dashEffect, true); originalMass = myBody.mass; originalDrag = myBody.drag; myBody.mass = entity.dashMass; myBody.drag = entity.dashDrag; if (entity.dashRenderer != null) { entity.dashRenderer.enabled = false; } return(condition); } if (condition && dashing) { currentDashLength += entity.executionInterval; if (currentDashLength > entity.dashLength) { condition = false; } } if (!condition && dashing) { dashing = false; myBody.mass = originalMass; myBody.drag = originalDrag; ManagesGame.getInstance().utilityFunctions.particleEmission(entity.dashEffect, false); if (entity.dashRenderer != null) { if (entity.deathController != null && !entity.deathController.hasDied()) { entity.dashRenderer.enabled = true; } } } return(condition); }