void Start() { GetComponent <Rigidbody2D>().freezeRotation = true; body = GetComponent <Rigidbody2D>(); ground = GetComponent <Grounding>(); anim = gameObject.GetComponent <Animator>(); }
void Start() { // assign the rigidbody component rb = GetComponent <Rigidbody2D>(); // assign Wall layer to variable walls = LayerMask.NameToLayer("Walls"); anchorLayer = LayerMask.NameToLayer("Anchors"); buttons = LayerMask.NameToLayer("Buttons"); // make sure that raycasts don't detect the colliders that they start in Physics2D.queriesStartInColliders = false; stamina = maxStamina; //rend = GetComponentInChildren<SpriteRenderer>(); leftTentacle.anchorPos = null; rightTentacle.anchorPos = null; switchTentacles = false; slingshot = Sling.None; bc = GetComponent <BoxCollider2D>(); anim = GetComponent <Animator>(); movement = Movement.Ground; groundingLR = Grounding.None; anchorGrip = AnchorGrip.None; rendTransform = rend.transform; increment[0] = Random.Range(0f, 10f); increment[1] = Random.Range(0f, 10f); saveController.LoadGame(); rend.flipX = faceDir == -1 ? true : false; Cursor.visible = false; endgame = false; }
void Update() { #region Order nearby anchorpoints by distance Functions.OrderByDistance(anchorPositions, transform.position); #endregion #region Find out which walls Akkoro is currently grounded to #region determine grounding for top & bottom if (groundingBoxes[0]) { groundingTB = Grounding.Bottom; } else if (groundingBoxes[3]) { groundingTB = Grounding.Top; } else { groundingTB = Grounding.None; } #endregion #region determine grounding for left & right if (groundingBoxes[1]) { groundingLR = Grounding.Left; } else if (groundingBoxes[2]) { groundingLR = Grounding.Right; } else { groundingLR = Grounding.None; } #endregion #endregion #region what movement state are we in? if (groundingTB != Grounding.Bottom && movement != Movement.Launch) { movement = Movement.Airborne; } else if (groundingTB == Grounding.Bottom) { movement = Movement.Ground; } #endregion #region Holding spacebar enables grip if (Input.GetKey(Variables.wallGrip) || Input.GetButton("Grip")) { if (groundingLR != Grounding.None || groundingTB == Grounding.Top) { gripping = true; movement = Movement.Wallclimb; } else { gripping = false; } } else { gripping = false; } if (stamina <= 0) { gripping = false; } #endregion #region movement if (!endgame) { // The player will only be able to move on walls when gripping if (gripping) { up = (Input.GetKey(KeyCode.W) || Input.GetAxis("Vertical") < 0f) ? 1 : 0; down = (Input.GetKey(KeyCode.S) || Input.GetAxis("Vertical") > 0f) ? -1 : 0; } else { up = 0; down = 0; } left = (Input.GetKey(KeyCode.A) || Input.GetAxis("Horizontal") > 0f) ? -1 : 0; right = (Input.GetKey(KeyCode.D) || Input.GetAxis("Horizontal") < 0f) ? 1 : 0; if (groundingLR == Grounding.Left) { left = 0; } else if (groundingLR == Grounding.Right) { right = 0; } } else { up = 0; down = 0; left = -1; right = 0; } // horizontal movement with A & D hor = (left + right) * speed; // vertical movement with W & S vert = (up + down) * speed; if (hor != 0) { if (faceDir != Mathf.Sign(hor)) { faceDir = (int)Mathf.Sign(hor); bc.offset = new Vector2(-bc.offset.x, bc.offset.y); } rend.flipX = faceDir == -1 ? true : false; } if (action) { hor = 0f; } if ((groundingLR == Grounding.Left && hor < 0) || (groundingLR == Grounding.Right && hor > 0) || hor == 0) { anim.SetBool("walkHor", false); } else if (hor != 0) { anim.SetBool("walkHor", true); } if ((groundingTB == Grounding.Top && vert > 0) || (groundingTB == Grounding.Bottom && vert < 0) || vert == 0) { anim.SetBool("walkVert", false); } else if (vert != 0) { anim.SetBool("walkVert", true); } #region set bool in animator if (movement == Movement.Airborne || movement == Movement.Launch) { anim.SetBool("inAir", true); } else { anim.SetBool("inAir", false); } if (groundingTB != Grounding.Bottom && groundingLR != Grounding.None && gripping) { anim.SetBool("onWall", true); } else { anim.SetBool("onWall", false); } if (groundingTB == Grounding.Top) { anim.SetBool("onCeil", true); } else { anim.SetBool("onCeil", false); } if (groundingTB == Grounding.Bottom) { anim.SetBool("onGround", true); } else { anim.SetBool("onGround", false); } if (groundingLR != Grounding.None && stamina <= 0) { anim.SetBool("dragWall", true); } else { anim.SetBool("dragWall", false); } if (movement == Movement.Wallclimb) { if (vert < 0) { rend.flipY = true; } else if (vert > 0) { rend.flipY = false; } } else { rend.flipY = false; } if (movement == Movement.Ground) { rend.flipY = false; } if (groundingLR == Grounding.Left) { rend.flipX = true; } else if (groundingLR == Grounding.Right) { rend.flipX = false; } if (groundingTB == Grounding.Bottom) { rend.flipY = false; } #endregion #endregion #region Calculate launch direction // if both tentacles are anchored, set the launch direction if (rightTentacle.state == Tentacles.Anchored && leftTentacle.state == Tentacles.Anchored) { // Visualize launch direction through gameobject transform launchDir.right = CalculateLaunchDirection(); } #endregion #region Tentacle logic TentacleGrab(ref leftTentacle, ref rightTentacle); TentacleGrab(ref rightTentacle, ref leftTentacle); if (leftTentacle.rot.rotation.z < rightTentacle.rot.rotation.z && switchTentacles) { SwitchTentacle(ref leftTentacle, ref rightTentacle); switchTentacles = false; } #endregion if (groundingTB == Grounding.None && ((leftTentacle.state == Tentacles.Anchored) != (rightTentacle.state == Tentacles.Anchored))) { stamina--; } #region Recover Stamina if (groundingTB == Grounding.Bottom) { stamina = maxStamina; } #endregion #region clamp stamina stamina = Mathf.Clamp(stamina, 0, maxStamina); #endregion if (gripping) { EnableGravity(false); } else { EnableGravity(true); } if (gripping && groundingTB != Grounding.Bottom) { //rendTransform.position = new Vector3(transform.position.x + GenerateNoise(0), transform.position.y + GenerateNoise(1), transform.position.z); rendTransform.localPosition = Vector3.zero; } else { rendTransform.localPosition = Vector3.zero; } if (rb.velocity.y > 0) { anim.SetBool("LaunchDirection", true); } else { anim.SetBool("LaunchDirection", false); } if (groundingTB == Grounding.Bottom) { anim.SetBool("canBeAirborne", true); } if (hor != 0 && !playingQuip) { //print("moving!"); quipTimer = 0f; } else { quipTimer += Time.deltaTime; } if (!playingQuip) { if (quipTimer >= quipTime) { print("start quip!"); playingQuip = true; quipTimer = 0f; // get length of quip here quipLength = 2f; } } else { if (quipTimer >= quipLength) { playingQuip = false; quipTimer = 0f; print("done playing quip!"); } } }
void Start() { GetComponent<Rigidbody2D>().freezeRotation = true; body = GetComponent<Rigidbody2D>(); ground = GetComponent<Grounding>(); anim = gameObject.GetComponent<Animator>(); }