- Home /
 
 
               Question by 
               klolololol · Jan 17, 2020 at 12:23 PM · 
                physicsrigidbodycollidervelocity  
              
 
              Vertical push doesn't let the object fall down instantly
An object (Wall) is continuously moving forward on the X axis with a simple script:
 public float speed = .2f;
 void FixedUpdate()
 {
     transform.Translate(speed, 0, 0);
 }
 
               It is pushing an other object (Penguin), which is affected by gravity. It can "jump" too, with a script of:
 public void Jump()
 {
     transform.position = new Vector3(transform.position.x, transform.position.y + 1.15f, transform.position.z);
 }
 
               When jumping, over a certain value of speed, like 0.2f, the Penguin is not falling to the ground until it reaches a velocity Vector of around (0.0, -10.0f, 0.0).
Setting the speed to 0.02f makes it instantly fall.
How can I achieve the same result with higher speed value?
I attached the setup of the two object in inspector:

 
                 
                inpector.png 
                (53.0 kB) 
               
 
              
               Comment
              
 
               
              Answer by Mark-Diax · Jan 17, 2020 at 01:18 PM
Before you do the jump code, try resetting the velocity of the penguin like this:
 private Rigidbody _rigidbody;
 
 public void Awake()
 {
      _rigidbody = GetComponent<Rigidbody>();
 } 
 
 public void Jump()
  {
      _rigidbody.velocity = Vector3.Zero;
      transform.position = new Vector3(transform.position.x, transform.position.y + 1.15f, transform.position.z);
  }
 
              Your answer