Example #1
0
    private void OnDrawGizmos()
    {
        GVStar star = GVUtil.GetNearStar(transform.position);

        if (star != null)
        {
            Gizmos.DrawLine(transform.position, transform.position + _direction);
            Gizmos.DrawLine(transform.position, transform.position + _upDir);
            Vector3 dirG = star.GetGravityDirection(transform.position);
//            Gizmos.DrawLine(transform.position, transform.position + dirG*5f);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        GVStar  star  = GVUtil.GetNearStar(transform.position);
        Vector3 dirG  = star.GetGravityDirection(transform.position);
        Vector3 dirUp = Vector3.Lerp(_upDir, -dirG, Time.deltaTime * 10f);

        _upDir     = dirUp;
        _direction = (_direction - dirG * Vector3.Dot(_direction, dirG)).normalized;
        transform.LookAt(transform.position + _direction, _upDir);

        float jumpVel = Vector3.Dot(dirUp, _velocity);

        jumpVel = Mathf.Clamp(jumpVel - Time.deltaTime * 30f, -10f, 20f);
        if (_isGround && Input.GetButtonDown("Jump"))
        {
            jumpVel = 20f;
        }
        _velocity = dirUp * jumpVel;

        // move
        Vector3 moveDir = Vector3.zero;

        moveDir = _cam.transform.up * Input.GetAxis("Vertical")
                  + _cam.transform.right * Input.GetAxis("Horizontal");

        Vector3 pos         = transform.position;
        float   inverseMove = 0f;

        if (moveDir.magnitude > 0f)
        {
            moveDir    = (moveDir - dirG * Vector3.Dot(moveDir, dirG)).normalized;
            _direction = Vector3.Lerp(_direction, moveDir, Time.deltaTime * 10f);
            Vector3 prevPos = pos;
            float   moveLen = Time.deltaTime * _speed;
            move(ref pos, moveDir, Time.deltaTime * _speed, true);
//            inverseMove = -Mathf.Min(0f,Vector3.Dot(dirG,pos - prevPos));
            inverseMove = _isGround?moveLen:0f;
        }

        // move jump
        if (move(ref pos, dirG, (-jumpVel * Time.deltaTime) + inverseMove, false))
        {
            _isGround = true;
        }
        else
        {
            _isGround = false;
        }

        trace(pos);
        transform.position = pos;
    }