본문 바로가기
프로그래밍/Unity

가감속

by ILove_NS_MoKa 2018. 9. 12.

    


  private float speed = 0f;

    private float _maxSpeed = 30f;

    private float forceMagnitude = 6f;

    private Vector3 movement = Vector3.zero;



void FixedUpdate()

    {

        _move = Input.GetAxis("Vertical");


        Move(0f, _move);

    }



    void Move(float h, float v)

    {

        if (v != 0 || h != 0)

        {

            // Set the movement vector based on the axis input.

            movement.Set(h, 0f, v);

            speed = Mathf.Min(speed + forceMagnitude * Time.deltaTime, _maxSpeed);

        }

        else

        {

            speed = Mathf.Max(speed - forceMagnitude * Time.deltaTime  * 1.5f, 0);

        }

        Debug.Log (speed);


        // Normalise the movement vector and make it proportional to the speed per second.

        movement = movement.normalized * speed * Time.deltaTime;


      //  Debug.Log(movement);


        // Move the player to it's current position plus the movement.

        rigid.MovePosition(transform.position + movement);

    }

'프로그래밍 > Unity' 카테고리의 다른 글

3d 수학 기초  (0) 2018.10.01
체력 비율 계산  (0) 2018.09.12
Velocity Addforc 차이점  (0) 2018.09.11
getting object local direction?  (0) 2018.09.11
유니티 자습서  (0) 2018.09.03