Hello Guest

Author Topic: Gravity slower when moving Rigidbody.  (Read 3820 times)

stevexu

  • Newbie
  • *
  • Posts: 29
    • View Profile
Gravity slower when moving Rigidbody.
« 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 ??
« Last Edit: September 26, 2013, 04:29:23 pm by stevexu »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Gravity slower when moving Rigidbody.
« Reply #1 on: September 27, 2013, 10:12:30 am »
Don't know, but where are you calling moveTowardRight from?

stevexu

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Gravity slower when moving Rigidbody.
« Reply #2 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();
        }

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Gravity slower when moving Rigidbody.
« Reply #3 on: September 28, 2013, 10:09:34 am »
I'm not sure what else to suggest - I've not tried this before.