예제 #1
0
    private void FixedUpdate()
    {
        if (isGrounded)
        {
            // rb.AddForce(dir.normalized * ((centroid==Vector3.up)?playerAnim.GetFloat("Forward"):1) * ((Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) ? 1 : 0) * Time.deltaTime * speed);
            //     if (Input.GetKeyDown(KeyCode.Space))

            rb.velocity = (rb.velocity.magnitude - Time.deltaTime * 20) * rb.velocity.normalized;       // deceleration
            // rb.AddForce(transform.right *  * Time.deltaTime * speed);
            //  rb.AddForce(Vector3.Cross(transform.forward, -transform.right) * rb.mass * 9.81f);
        }
        else
        {
            rb.AddForce(-Vector3.up * 279f * ((Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0)?gravFactor:1)
                        / (rb.velocity.magnitude + 1));
            //var rot = transform.rotation;
            //rot.x = 0;
            //rot.z = 0;
            //rb.MoveRotation(rot);
        }

        if (Input.GetAxisRaw("Jump") > 0 && !isJumping)
        {
            //   keyHeld += Time.deltaTime;
            //   rb.isKinematic = true;

            //      if (Physics.OverlapSphere(transform.position, .25f,1<<LayerMask.NameToLayer("Terrain")).Length == 0)
            //    {
            CreateChunk();
            ManipulateTerrain();
            Batcher.AddToBatch(this.gameObject, transform.position);
            flyFactor   = flySpeed;
            rb.velocity = Vector3.zero;
            rb.AddForce(transform.up * Time.deltaTime * 50 * rockSpeed, ForceMode.Impulse);
            jumpedTimer = 0;
            isJumping   = true;

            //     }
        }
        //if (!Input.GetKey(KeyCode.Space))
        //{
        //    rb.isKinematic = false;
        //}

        if (Input.GetKeyUp(KeyCode.Space) && !isJumping)
        {
        }


        //if(Input.GetKey(KeyCode.Space))
        //    transform.Translate((transform.forward * Input.GetAxis("Vertical") + transform.right * Input.GetAxis("Horizontal")) * Time.deltaTime * rockSpeed, Space.World);



        if (Input.GetKeyUp(KeyCode.Space))
        {
            rb.isKinematic = false;
        }



        //if (Input.GetKey(KeyCode.A))
        //    rb.AddForce(-rightDir * Time.deltaTime * speed * (isGrounded ? 1 : (flyFactor > 0 ? flyFactor : 0)));
        //if (Input.GetKey(KeyCode.D))
        //    rb.AddForce(rightDir * Time.deltaTime * speed * (isGrounded ? 1 : (flyFactor > 0 ? flyFactor : 0)));
        //if (Input.GetKey(KeyCode.W))
        //    rb.AddForce(dir * Time.deltaTime * speed * (isGrounded ? 1 : (flyFactor > 0 ? flyFactor : 0)));
        //if (Input.GetKey(KeyCode.S))
        //    rb.AddForce(-dir * Time.deltaTime * speed * (isGrounded ? 1 : (flyFactor > 0 ? flyFactor : 0)));

        rb.AddForce((dir * Input.GetAxis("Vertical") + rightDir * Input.GetAxis("Horizontal")) * Time.deltaTime * speed * (isGrounded ? 1 : (flyFactor > 0 ? flyFactor : 0)));
        // rb.AddForce(-transform.up * rb.mass * 7f);

        if (isJumping)
        {
            rb.AddForce(transform.up * Time.deltaTime * 15 * rockSpeed, ForceMode.Impulse);
        }
    }