Problem with Speed Up Object

Discuss issues specific the Java port of Box2D
D3ftp
Posts: 1
Joined: Wed May 21, 2014 1:20 pm

Problem with Speed Up Object

Postby D3ftp » Wed May 21, 2014 1:39 pm

How to speed up object.? i try change

Code: Select all

              vec.x = vec.x +40 ;
              MyFirstBody.setLinearVelocity(vec);
 
              MyFirstBody.applyLinearImpulse(new Vector2(0, 50), MyFirstBody.getWorldCenter(), true);

to

Code: Select all

package com.mygdx.game2; 

          vec.x = vec.x +40000 ;
              MyFirstBody.setLinearVelocity(vec);
 
              MyFirstBody.applyLinearImpulse(new Vector2(0, 50), MyFirstBody.getWorldCenter(), true);


Code: Select all

   
but it dont change my object speed.
[code]package com.mygdx.game2

 public class MyGdxGame implements ApplicationListener { 
      World world = new World(new Vector2(0, -100), true); 
      Box2DDebugRenderer debugRenderer; 
      OrthographicCamera camera; 
      static final float BOX_STEP=1/60f; 
      static final int BOX_VELOCITY_ITERATIONS=6; 
      static final int BOX_POSITION_ITERATIONS=2; 
      static final float WORLD_TO_BOX=0.01f; 
      static final float BOX_WORLD_TO=100f; 
     
      private Body MyFirstBody;
      private Body Mybody2;
     
      @Override 
      public void create() {           
           camera = new OrthographicCamera(); 
           camera.viewportHeight = 320; 
           camera.viewportWidth = 480; 
           
           camera.position.set(camera.viewportWidth * .5f, camera.viewportHeight * .5f, 0f); 
           camera.update(); 
             
           //Ground body 
           BodyDef groundBodyDef =new BodyDef(); 
           groundBodyDef.position.set(new Vector2(0, 10)); 
           Body groundBody = world.createBody(groundBodyDef); 
           PolygonShape groundBox = new PolygonShape(); 
           groundBox.setAsBox((camera.viewportWidth) * 2, 10.0f); 
           groundBody.createFixture(groundBox, 0.0f);
           
           //Dynamic Body 
           BodyDef body1 = new BodyDef();
           body1.type = BodyType.DynamicBody;
           body1.bullet = true;
           body1.position.set(50, 200);
           MyFirstBody = world.createBody(body1);
           

           CircleShape ball = new CircleShape();
           ball.setRadius(8);
           
           FixtureDef fixture = new FixtureDef();
           fixture.shape = ball;
           fixture.density = 5.5f;
           fixture.friction = 1f;
           fixture.restitution = 100f;
           
           Fixture fixture2 = MyFirstBody.createFixture(fixture);
 
           debugRenderer = new Box2DDebugRenderer(); 
      } 
      @Override 
      public void dispose() { 
      } 
      @Override 
      public void render() {           
           Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
           
           
           if( Gdx.input.isKeyPressed(Keys.A) ){
              Vector2 vec = MyFirstBody.getLinearVelocity();
              //MyFirstBody.applyForce(new Vector2(-10000,0),new Vector2(10, 0), false);
              vec.x = vec.x -(int)Math.max(1, 1000) ;
              MyFirstBody.setLinearVelocity(vec);
           }
           
           if( Gdx.input.isKeyPressed(Keys.D) ){
             // MyFirstBody.applyForce(new Vector2(10000,0),new Vector2(10, 0), true);
              
              Vector2 vec = MyFirstBody.getLinearVelocity();
              //MyFirstBody.applyForce(new Vector2(-10000,0),new Vector2(10, 0), false);
              vec.x = vec.x +400 ;
              MyFirstBody.setLinearVelocity(vec);
 
              MyFirstBody.applyLinearImpulse(new Vector2(0, 5000), MyFirstBody.getWorldCenter(), true);
           }
           
           if( Gdx.input.isKeyPressed(Keys.W) ){
           //   MyFirstBody.applyForce(new Vector2(0,10000000),new Vector2(1000, 100), true);
              MyFirstBody.setLinearVelocity(new Vector2(100000, 1000*100));
              
              //to change velocity by 10
               float impulse = MyFirstBody.getMass() * 1000;
              // MyFirstBody.applyLinearImpulse(new Vector2(0,impulse), Mybody2.getWorldCenter(), true);
           }
           
           debugRenderer.render(world, camera.combined); 
           world.step(BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS); 
      } 
      @Override 
      public void resize(int width, int height) { 
      } 
      @Override 
      public void pause() { 
      } 
      @Override 
      public void resume() { 
      } 
 } 

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Problem with Speed Up Object

Postby irresistible force » Thu May 22, 2014 7:02 am

There is a limit of 2 meters per time step. I think you need to scale down the physics dimensions - your circle is the size of a small building. See also: https://www.iforce2d.net/b2dtut/gotchas#speedlimit


Return to “Java”



Who is online

Users browsing this forum: No registered users and 2 guests