2D Toolkit Forum

2D Toolkit => Support => Topic started by: stevexu on September 26, 2013, 04:25:04 pm

Title: Gravity slower when moving Rigidbody.
Post by: stevexu on September 26, 2013, 04:25:04 pm
I have a tk2dSprit with a Rigidbody  attach to it,
When I move a Rigidbody using this script:
Code: [Select]
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            moveTowardRight();
        }

  void moveTowardRight()
   {
       cleanFlag(STATE_STANDBY);
       cleanFlag(STATE_RUN_LEFT);

       addFlag(STATE_RUN_RIGHT);

       Vector3 vy = rigidbody.velocity.y * (hasFlag(STATE_JUMP) ? Vector3.up : Vector3.zero);

       rigidbody.velocity = vy + Vector3.right * SPEED;
   }


it does go forward but has a decreased gravity, so it looks like it floats but when I release the key that makes my rigidbody move it drops down way faster. All the settings of my rigidbody are default so why does this happen ??
Title: Re: Gravity slower when moving Rigidbody.
Post by: unikronsoftware on September 27, 2013, 10:12:30 am
Don't know, but where are you calling moveTowardRight from?
Title: Re: Gravity slower when moving Rigidbody.
Post by: stevexu on September 28, 2013, 04:58:01 am
In FixedUpdate.

 I checked, the  rigidbody.velocity .y  is  always 0 , and  the   Physics.gravity  is always -9.8,  and nobody collid with rigidbody

Code: [Select]
    void FixedUpdate()
    {
      //  rigidbody.WakeUp();
        detectKey();
        updateAniByState();

        System.Diagnostics.Debug.Assert(rigidbody.position.z == -0.5);

        print("rigidbody.velocity  = " + rigidbody.velocity + " rbody = " + rigidbody);
    }




    void detectKey()
    {
       
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            moveTowardRight();
        }
        else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            // rigidbody.transform.Translate(Vector3.left * SPEED * Time.deltaTime);
            moveTowardLeft();
        }
Title: Re: Gravity slower when moving Rigidbody.
Post by: unikronsoftware on September 28, 2013, 10:09:34 am
I'm not sure what else to suggest - I've not tried this before.