/// <summary> /// Resets the movement settings to their "Normal" values /// </summary> private void ResetMovementVars() { // Setting the "Currrent" properties to be the "Normal" values currentMoveVars = GetMovementVarsByName("Normal"); // Setting the rigidbody gravity rigid.gravityScale = currentMoveVars.gravity; }
/// <summary> /// Activates when the BOX TRIGGER first touches another trigger /// </summary> /// <param name="other"></param> void OnTriggerEnter2D(Collider2D other) { // IF the other collider is a Platform... if (other.gameObject.tag == "Platform") { // Casting to the correct collider type BoxCollider2D otherBox = (BoxCollider2D)other; // Processing the platform as a proper platform ProcessAsPlatform(otherBox, true); // Playing the landing audio clip (assuming it's defined) if (currentMoveVars.landingSound != string.Empty && !audioMng.IsPlaying(currentMoveVars.landingSound)) { audioMng.PlayAudio(currentMoveVars.landingSound); } } // IF the other collider is Water... if (other.gameObject.tag == "Water") { // Cut velocity by 20% rigid.velocity *= 0.8f; // Setting the water movement variables currentMoveVars = GetMovementVarsByName("Water"); // Playing the "Water Entered" audio (if it's defined) if (currentMoveVars.settingsAppliedSound != string.Empty) { audioMng.PlayAudio(currentMoveVars.settingsAppliedSound); } } // IF the other collider is a Checkpoint Trigger... if (other.gameObject.tag == "Checkpoint Trigger") { ChangeCheckpoint(other.gameObject.transform.parent); } // IF the other collider is the goal... if (other.gameObject.tag == "Finish") { // Disabling input inputEnabled = false; // Playing the Level Complete audio + Stopping the background music audioMng.PlayAudio("Level Complete"); audioMng.StopAudio("Nowhere Land"); } }
/// <summary> /// Returns the movement settings instance with the name that EXACTLY matches the given name /// </summary> /// <param name="name"></param> /// <returns></returns> public PlayerMovementSettings GetMovementVarsByName(string name) { PlayerMovementSettings result = null; for (int num = 0; num < movementVars.Count; num++) { if (movementVars[num].name == name) { result = movementVars[num]; num = movementVars.Count; } } return(result); }
/// <summary> /// Activates when the BOX TRIGGER first touches another trigger /// </summary> /// <param name="other"></param> void OnTriggerEnter2D(Collider2D other) { // IF the other collider is a Platform... if (other.gameObject.tag == "Platform") { // Casting to the correct collider type BoxCollider2D otherBox = (BoxCollider2D)other; // Processing the platform as a proper platform ProcessAsPlatform(otherBox, true); // Playing the landing audio clip (assuming it's defined) if (currentMoveVars.landingSound != string.Empty && !audioMng.IsPlaying(currentMoveVars.landingSound)) { audioMng.PlayAudio(currentMoveVars.landingSound); } } // IF the other collider is a Passthrough Platform... if (other.gameObject.tag == "Passthrough") { // Getting the rotation direction of the passthrough platform float platformAngle = other.transform.eulerAngles.z; Vector2 passthroughNormal = Vector2.up; passthroughNormal.x = -1 * Mathf.Sin((platformAngle / 180) * Mathf.PI); passthroughNormal.y = Mathf.Cos((platformAngle / 180) * Mathf.PI); // Getting the angle between the passthrough platform normal and the player velocity float angleBetween = Vector2.SignedAngle(passthroughNormal, rigid.velocity.normalized); // Determining if the passthrough platform should be treated as solid if (!ignorePassthrough && Mathf.Abs(angleBetween) >= 90) { // Casting to the correct collider type BoxCollider2D otherBox = (BoxCollider2D)other; // Processing the platform as a proper platform ProcessAsPlatform(otherBox, true); // Setting the current velocity to not move in the direction of the passthrough normal float scaleVal = Vector2.Dot(rigid.velocity, passthroughNormal) / Vector2.Dot(passthroughNormal, passthroughNormal); rigid.velocity -= passthroughNormal * scaleVal; // Playing the landing audio clip (assuming it's defined) if (currentMoveVars.landingSound != string.Empty && !audioMng.IsPlaying(currentMoveVars.landingSound)) { audioMng.PlayAudio(currentMoveVars.landingSound); } } } // IF the other collider is Water... if (other.gameObject.tag == "Water") { // Cut velocity by 20% rigid.velocity *= 0.8f; // Setting the water movement variables currentMoveVars = GetMovementVarsByName("Water"); // Playing the "Water Entered" audio (if it's defined) if (currentMoveVars.settingsAppliedSound != string.Empty) { audioMng.PlayAudio(currentMoveVars.settingsAppliedSound); } } // IF the other collider is a Checkpoint Trigger... if (other.gameObject.tag == "Checkpoint Trigger") { ChangeCheckpoint(other.gameObject.transform.parent); } // IF the other collider is the goal... if (other.gameObject.tag == "Finish") { // Disabling input inputEnabled = false; // Playing the Level Complete audio + Stopping the background music audioMng.PlayAudio("Level Complete"); audioMng.StopAudio("Nowhere Land"); } }
public PlayerSettings() { Spatial = new PlayerSpatialSettings(); Movement = new PlayerMovementSettings(); AnimationDuration = new PlayerAnimationDurationSettings(); }