简体   繁体   中英

Simple velocity will not function?

I have two lines of code, that in every way I can tell, are exactly the same. Yet one works the way it should, while the other one does nothing. I know it sounds inane but this is driving me nuts and any advice would be a life-saver:

First the one that works:

public Rigidbody2D pBlock;

if (playerReference.GetComponent<Player>()){
Debug.Log ("got to debug");
            pBlock.velocity = new Vector2(10, 0);
        }

Now the one that doesn't:

       public Rigidbody2D playerRigid;

  public void Update()
    {
        if (conveyorBeltLeft.conveyorPlayerLeft) {
         Debug.Log ("got to debug");
            playerRigid.velocity = new Vector2(-100, 500000);
        }

The first one, the object moves, the second one, it doesn't. In both of them the debug goes off. Please someone explain this to me is everything I've learned about Unity so far entirely wrong?

Some thoughts:

  • Check that playerRigid.isKinematic is false
  • Check that playerRigid is not asleep ( IsSleeping() should return false)
  • Check that there are no constraints on playerRigid (ie playerRigid.constraints is set to None )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM