private void OnSceneGUI() { serializedObject.Update(); Vector3 heightArrowOrigin = controller2D.transform.position + new Vector3(-1, -1); Vector3 jumpHeightArrowEndPoint = heightArrowOrigin + new Vector3(0, controller2D.jumpHeight); Vector3 runArrowOrigin = controller2D.transform.position + new Vector3(0, -1f); Vector3 runArrowEndPoint = runArrowOrigin + new Vector3(controller2D.runSpeed, 0); Vector3 jumpArcOrigin = runArrowOrigin; Handles.color = Color.white; Handles.DrawLine(heightArrowOrigin, jumpHeightArrowEndPoint); controller2D.jumpHeight = Handles.ScaleValueHandle(controller2D.jumpHeight, jumpHeightArrowEndPoint, Quaternion.LookRotation(Vector3.up), 10, Handles.ArrowHandleCap, 0.1f); Handles.DrawLine(runArrowOrigin, runArrowEndPoint); controller2D.runSpeed = Handles.ScaleValueHandle(controller2D.runSpeed, runArrowEndPoint, Quaternion.LookRotation(Vector3.right), 10, Handles.ArrowHandleCap, 0.1f); float scaledGravity = Physics2D.gravity.y * controller2D.gameObject.GetComponent <Rigidbody2D>().gravityScale; Vector2 verticalJumpVelocity = KinematicHelper.CalculateInitialVelocity(controller2D.transform.position, controller2D.transform.position + Vector3.up * controller2D.jumpHeight, controller2D.jumpHeight, scaledGravity); Vector3[] arcPoints = KinematicHelper.CalculateArcArray(new Vector3(controller2D.runSpeed, verticalJumpVelocity.y), 10, scaledGravity); for (int i = 0; i < arcPoints.Length - 1; i++) { Handles.DrawLine(runArrowOrigin + arcPoints[i], runArrowOrigin + arcPoints[i + 1]); } serializedObject.ApplyModifiedProperties(); if (GUI.changed) { EditorUtility.SetDirty(controller2D); EditorSceneManager.MarkSceneDirty(controller2D.gameObject.scene); } //Handles.Label(controller2D.transform.position, "Hello World"); //Handles.color = Color.blue; //float size = HandleUtility.GetHandleSize(controller2D.transform.position); //controller2D.jumpHeight = Handles.ScaleValueHandle(controller2D.jumpHeight, controller2D.transform.position + new Vector3(-1, -1), Quaternion.LookRotation(Vector3.up), controller2D.jumpHeight * 7.5f, Handles.ArrowHandleCap, 0.5f); /* Handles.ArrowHandleCap( * 0, * controller2D.transform.position + new Vector3(3f, 0f, 0f), * controller2D.transform.rotation * Quaternion.LookRotation(Vector3.up), * 1, * EventType.Repaint * ); */ }
public void Move(float move, bool crouch, bool jump) { // If crouching, check to see if the character can stand up if (!crouch) { // If the character has a ceiling preventing them from standing up, keep them crouching if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround)) { crouch = true; } } //only control the player if grounded or airControl is turned on if (m_Grounded || m_AirControl) { // If crouching if (crouch) { // Reduce the speed by the crouchSpeed multiplier move *= m_CrouchSpeed; // Disable one of the colliders when crouching if (m_CrouchDisableCollider != null) { m_CrouchDisableCollider.enabled = false; } } else { // Enable the collider when not crouching if (m_CrouchDisableCollider != null) { m_CrouchDisableCollider.enabled = true; } } // Move the character by finding the target velocity Vector3 targetVelocity = new Vector2(move * runSpeed, m_Rigidbody2D.velocity.y); // And then smoothing it out and applying it to the character m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref velocity, m_MovementSmoothing); // If the input is moving the player right and the player is facing left... if (move > 0 && !m_FacingRight) { // ... flip the player. Flip(); } // Otherwise if the input is moving the player left and the player is facing right... else if (move < 0 && m_FacingRight) { // ... flip the player. Flip(); } } // If the player should jump... if (m_Grounded && jump) { // Add a vertical force to the player. Vector2 verticalJumpVelocity = KinematicHelper.CalculateInitialVelocity(transform.position, transform.position + Vector3.up * jumpHeight, jumpHeight, Physics2D.gravity.y * m_Rigidbody2D.gravityScale); m_Grounded = false; m_Rigidbody2D.AddForce(verticalJumpVelocity, ForceMode2D.Impulse); } }