How to speed up object.? i try change
to
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() {
}
}