// Use this for initialization void Awake() { topBound = GameObject.Find("TopBoundary"); rightBound = GameObject.Find("RightBoundary"); bottomBound = GameObject.Find("BottomBoundary"); leftBound = GameObject.Find("LeftBoundary"); topBoundScript = topBound.GetComponent <BoundaryScript>(); rightBoundScript = rightBound.GetComponent <BoundaryScript>(); bottomBoundScript = bottomBound.GetComponent <BoundaryScript>(); leftBoundScript = leftBound.GetComponent <BoundaryScript>(); }
void Start() { boundaryScript = FindObjectOfType <BoundaryScript>(); JumpHeight = jumpHeight; aState = AIR_STATE.FALLING; mainCam = Camera.main; //calculate jump speed based on jump height and the gravity using a kinematic equation //jumpSpeed = Mathf.Sqrt(2f * jumpHeight * Mathf.Abs(Physics2D.gravity.y)); //sqrt((2 * d) / a) = t //jump time = sqrt(2 * jumpHeight / gravity); //jump speed = jump height / jump time //know jumpHeight and timetoJumpApex //need to solve for gravity and jumpSpeed //d = vi * t + (1/2) * a * t^2 //solve for gravity gravity = (2 * jumpHeight) / (timeToJumpApex * timeToJumpApex); //temp ~ Physics2D.gravity = new Vector2(Physics2D.gravity.x, -gravity); //solve for jumpSpeed jumpSpeed = gravity * timeToJumpApex; //debugging if (enableFlyMode) { rb.bodyType = RigidbodyType2D.Static; playerCollider.enabled = false; transform.position = new Vector2(mainCam.transform.position.x, mainCam.transform.position.y - mainCam.orthographicSize / 2); return; } // StartCoroutine(CheckIfDead()); WorldEventSystem.OnTimerInterrupted += IsPlayerOutOfBounds; WorldEventSystem.OnPlayerActionEvaluated += EvaluatePlayerDeath; }
// Use this for initialization void Start() { instance = this; }