protected AcceptInputFrom m_ReadInput; //To get the input protected void start() { m_Animator = GetComponentInParent <AnimatorPlayers> (); m_Movement = GetComponentInParent <BaseMovementAbility> (); //m_ReadInput = GetComponentInParent<AcceptInputFrom>(); m_ReadInput = transform.parent.GetComponent <AcceptInputFrom> (); m_AOEProjectileAngle = 360 / m_NumberOfAOEProjectiles; GetComponent <AnimationCallBackManager> ().registerCallBack(this); //Setting up trail renderers. m_TrailRenderers = GetComponentsInChildren <TrailRenderer>(); m_TrailRenderersActive = new bool[m_TrailRenderers.Length]; m_TrailRenderersTimeAlive = new float[m_TrailRenderers.Length]; m_TrailRenderersCurrentTime = new float[m_TrailRenderers.Length]; for (int i = 0; i < m_TrailRenderers.Length; i++) { m_TrailRenderersActive[i] = false; m_TrailRenderersTimeAlive[i] = m_TrailRenderers[i].time; m_TrailRenderersCurrentTime[i] = 0; } m_ChargingEffectMat = m_ChargingEffectObject.renderer.material; m_SFX = SFXManager.Instance; }
void OnCollisionExit(Collision collision) { //Only move players if (collision.gameObject.tag != Constants.COLLIDE_WITH_MOVING_PLATFORM_STRING) { return; } //Null check for the movement ability BaseMovementAbility movement = (BaseMovementAbility)collision.transform.parent.gameObject.GetComponent <BaseMovementAbility> (); if (movement == null) { return; } //Check if the player should be added or changed for (int i = 0; i < m_PlayersToMove.Count; i++) { if (movement == m_PlayersToMove[i].movement) { //Check if the player should be removed from the array or flaged to be removed next frame if (m_PlayersToMove[i].foundLastFrame == true) { m_PlayersToMove[i] = new PlayersToMove(m_PlayersToMove[i].movement, m_PlayersToMove[i].normal, false); } else { //Debug.Log(m_PlayersToMove[i].movement.gameObject.name+ " removed"); //m_PlayersToMove.RemoveAt(i); } } } }
//When a player lands on the trampoline, launch them to the launch point void OnTriggerEnter(Collider other) { if (other.tag == Constants.PLAYER_STRING) { m_LaunchVelocity = (transform.FindChild(LAUNCHPOINT_NAME).position - transform.position).normalized * m_LaunchAmount; BaseMovementAbility Base = other.gameObject.GetComponent <BaseMovementAbility>(); Base.LaunchJump(m_LaunchVelocity, m_LaunchTimer); } }
//Add the players currently in the trigger to the list of players. void OnTriggerStay(Collider other) { //Gets the basemovement ability component from the objects BaseMovementAbility player = other.gameObject.GetComponent <BaseMovementAbility> (); //If the component existsts then add it to the list if (player != null) { if (!m_Players.Contains(player)) { m_Players.Add(player); } } }
//When the player collides with this platform void OnCollisionStay(Collision collision) { //Only move players if (collision.gameObject.tag != Constants.COLLIDE_WITH_MOVING_PLATFORM_STRING) { return; } //Null check for the movement ability BaseMovementAbility movement = (BaseMovementAbility)collision.transform.parent.gameObject.GetComponent <BaseMovementAbility> (); if (movement == null) { return; } //Get the average direction that the player has collided with the moving platform ContactPoint[] contacts = collision.contacts; Vector3 averageNormal = Vector3.zero; foreach (ContactPoint contactPoint in contacts) { averageNormal += contactPoint.normal; Debug.DrawRay(contactPoint.point, contactPoint.normal, Color.white); } averageNormal /= -contacts.Length; //Check if the player should be added or changed bool found = false; for (int i = 0; i < m_PlayersToMove.Count; i++) { if (movement == m_PlayersToMove[i].movement) { m_PlayersToMove[i] = new PlayersToMove(movement, averageNormal, true); found = true; } } if (found == false) { m_PlayersToMove.Add(new PlayersToMove(movement, averageNormal, true)); Debug.Log(m_PlayersToMove[m_PlayersToMove.Count - 1].movement.gameObject.name + " added"); } }
public PlayersToMove(BaseMovementAbility aMovement, Vector3 aNormal, bool wasFoundLastFrame) { movement = aMovement; normal = aNormal; foundLastFrame = wasFoundLastFrame; }
// Use this for initialization void Start() { Characters currentCharacter; switch (transform.parent.name) { case Constants.ALEX_STRING: currentCharacter = Characters.Alex; break; case Constants.DEREK_STRING: currentCharacter = Characters.Derek; break; case Constants.ZOE_STRING: currentCharacter = Characters.Zoe; break; default: #if DEBUG || UNITY_EDITOR Debug.LogError("parent is named wrong"); #endif currentCharacter = Characters.Zoe; break; } //Check if player one if (GameData.Instance.PlayerOneCharacter == currentCharacter) { m_Player = 1; } else { m_Player = 2; } //gets reference to sound manager m_SFX = SFXManager.Instance; //Gets reference to hud m_Hud = GameObject.FindGameObjectWithTag(Constants.HUD).GetComponent <Hud>(); //setting initial values for the timers m_HealthRegenTimer = HealthRegenTime; m_InvulnerabilityTimer = InvulnerabilityTimer; //setting the total health m_TotalHealth = m_Health; //Set Health in hud m_Hud.SetHealth(m_TotalHealth, m_Player); m_PlayerRenderer = gameObject.GetComponentInChildren <SkinnedMeshRenderer>(); //Get the players movement for knockback m_Movement = GetComponent <BaseMovementAbility> (); #if DEBUG || UNITY_EDITOR if (i_InvulnerableMaterial == null) { Debug.LogError("put the invulnerable material on this script"); } #endif m_DefaultMaterial = m_PlayerRenderer.materials[0]; //Load player light m_PlayerLight = GetComponent <PlayerLightController>(); }
//Moves the platform towards the next destination void MoveToDestination() { //Get the the next destinations position Vector3 destinationPosition = m_Destinations [m_DestinationIndex].position; //Get the direction vector between them Vector3 destinationDirection = destinationPosition - transform.position; //Get the magnitude of that direction to use for a proximity check once close enough m_DistanceToNextPlatform = destinationDirection.magnitude; float Speed; if (m_UseConstantSpeed) { Speed = m_PlatformSpeed; } else { if (m_TimeForPlatforms.Length < m_DestinationIndex) { Debug.Log("Problem"); } Speed = CalculateSpeed(m_TimeForPlatforms[m_DestinationIndex], m_DestinationIndex, m_PreviousDestinationIndex); } //Move the platform along that direction over time m_AmountToMovePlayer = destinationDirection.normalized * Speed * Time.deltaTime; if (m_AmountToMovePlayer.magnitude > m_DistanceToNextPlatform) { m_AmountToMovePlayer = m_AmountToMovePlayer.normalized * m_DistanceToNextPlatform; } m_TargetMove += m_AmountToMovePlayer; Vector3 move = Vector3.Lerp(Vector3.zero, m_TargetMove, i_MoveLerpAmount); transform.position += move; m_TargetMove -= move; //Check if their are any players on the platform if (m_PlayersToMove.Count > 0) { for (int i = 0; i < m_PlayersToMove.Count; i++) { //Calculate the amount to move the player Vector3 amountToMove = Vector3.zero; //Get related variables from the struct BaseMovementAbility movement = m_PlayersToMove[i].movement; Vector3 normal = m_PlayersToMove[i].normal; //Check if the player is on top of the platform if (Vector3.Dot(Vector3.up, normal) > 0.5f) { //Move the player as much at this platform is moving amountToMove = move; amountToMove.y += 0.01f; } //Check if we are in front of the platform else if (Vector3.Dot(move, normal) > 0.0f) { //Move the layer based on how much we are overlapping the player Vector3 playerMovement = movement.GetMovementThisFrame(); playerMovement.y = 0.0f; amountToMove = Vector3.Scale(normal, move - playerMovement); amountToMove.y = 0.0f; } //Move the player movement.RequestInstantMovement(amountToMove); if (m_PlayersToMove[i].foundLastFrame == false) { Debug.Log("removing: " + m_PlayersToMove[i].movement.gameObject.name); m_PlayersToMove.RemoveAt(i); } } } }
protected void start() { m_Animator = GetComponentInParent<AnimatorPlayers> (); m_Movement = GetComponentInParent<BaseMovementAbility> (); //m_ReadInput = GetComponentInParent<AcceptInputFrom>(); m_ReadInput = transform.parent.GetComponent<AcceptInputFrom> (); m_AOEProjectileAngle = 360 / m_NumberOfAOEProjectiles; GetComponent<AnimationCallBackManager> ().registerCallBack (this); //Setting up trail renderers. m_TrailRenderers = GetComponentsInChildren<TrailRenderer>(); m_TrailRenderersActive = new bool[m_TrailRenderers.Length]; m_TrailRenderersTimeAlive = new float[m_TrailRenderers.Length]; m_TrailRenderersCurrentTime = new float[m_TrailRenderers.Length]; for(int i = 0; i < m_TrailRenderers.Length; i++) { m_TrailRenderersActive[i] = false; m_TrailRenderersTimeAlive[i] = m_TrailRenderers[i].time; m_TrailRenderersCurrentTime[i] = 0; } m_ChargingEffectMat = m_ChargingEffectObject.renderer.material; m_SFX = SFXManager.Instance; }
// Use this for initialization void Start() { Characters currentCharacter; switch (transform.parent.name) { case Constants.ALEX_STRING: currentCharacter = Characters.Alex; break; case Constants.DEREK_STRING: currentCharacter = Characters.Derek; break; case Constants.ZOE_STRING: currentCharacter = Characters.Zoe; break; default: #if DEBUG || UNITY_EDITOR Debug.LogError("parent is named wrong"); #endif currentCharacter = Characters.Zoe; break; } //Check if player one if (GameData.Instance.PlayerOneCharacter == currentCharacter) { m_Player = 1; } else { m_Player = 2; } //gets reference to sound manager m_SFX = SFXManager.Instance; //Gets reference to hud m_Hud = GameObject.FindGameObjectWithTag(Constants.HUD).GetComponent<Hud>(); //setting initial values for the timers m_HealthRegenTimer = HealthRegenTime; m_InvulnerabilityTimer = InvulnerabilityTimer; //setting the total health m_TotalHealth = m_Health; //Set Health in hud m_Hud.SetHealth (m_TotalHealth, m_Player); m_PlayerRenderer = gameObject.GetComponentInChildren<SkinnedMeshRenderer>(); //Get the players movement for knockback m_Movement = GetComponent<BaseMovementAbility> (); #if DEBUG || UNITY_EDITOR if(i_InvulnerableMaterial == null) { Debug.LogError("put the invulnerable material on this script"); } #endif m_DefaultMaterial = m_PlayerRenderer.materials[0]; //Load player light m_PlayerLight = GetComponent<PlayerLightController>(); }