Exemple #1
0
    void UpdateRopeObject()
    {
        Vector3 dirToTarget = (transform.position - ropeObject.transform.position).normalized;

        velocity = transform.position - lastPos;

        lastPos = transform.position;

        if (debug)
        {
            Debug.DrawRay(ropeObject.transform.position, ropeObject.getVelocity * 3f, Color.red);
        }

        if (distanceToTarget > ropeLength)
        {
            Vector3 dirToRope = (transform.position - ropeObject.transform.position).normalized;
            if (distanceToTarget > ropeLength + elasticity)
            {
                Vector3 outerCirclePoint = transform.position - dirToTarget * (ropeLength + elasticity);
                ropeObject.transform.position = outerCirclePoint;

                float   distanceFromMiddleX = transform.position.x - ropeObject.transform.position.x;
                Vector3 bounceSurface       = Quaternion.Euler(0f, 0f, 90f) * dirToTarget * Mathf.Sign(distanceFromMiddleX);
                Vector3 bounceVelocity      = Vector3.Reflect(dirToTarget, bounceSurface).normalized;

                ropeObject.AddVelocity(bounceVelocity * Mathf.Abs(distanceFromMiddleX) * Time.deltaTime);

                ropeObject.SetVelocity(velocity * inheritedVelocity + ropeObject.getVelocity * (1f - Time.deltaTime));
            }

            ropeObject.AddVelocity(dirToRope * Time.deltaTime);
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        //gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;

        /*float inptZ = Input.GetAxis("Horizontal");
         * if (inptZ != 0) {
         *      if (inptZ > 0) inptZ = 1;
         *      else inptZ = -1;
         * }*/
        float inptZ = 0;

        if (Input.GetKey(KeyCode.A))
        {
            inptZ = -1;
        }
        else if (Input.GetKey(KeyCode.D))
        {
            inptZ = 1;
        }
        float inptY = Input.GetAxis("Vertical");

        _animator.SetFloat("inputZ", inptZ);
        CheckMousePos();
        if (inptZ != 0)
        {
            Move(inptZ);
        }
        if (inptY != 0 && !_phyo.InAir)
        {
            //_phyo.InAir = true;
            _animator.SetBool("inAir", _phyo.InAir);
            _animator.Play("Armed-Jump");
            //dir2Cursor*jumpspeed
            //_phyo.AddAirForce(Dir2Cursor() * _jumpSpeed);
            _phyo.AddAirForce(new Vector3(inptZ * 2, _jumpSpeed, 0));
        }


        if (Input.GetAxis("Jump") != 0)
        {
            //_animator.Play("Armed-Jump");
            //Roll(inptZ);
        }
        CheckBlock();
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Roll(inptZ);
        }
        CheckAttack();
        if (_rolling)
        {
            _phyo.AddVelocity(new Vector3(inptZ * 30, 0, 0));
        }
    }