project: I am making a simple project in which i want to be able to make a kinematic body and move it from point x to y. There doesn't seem to be much directly on "Creating kinematic bodies". i've been following a few different tutorials on implementing kinematic bodies because i couldnt find one that specified how to do it correctly.
Problem: It seems to be a simple fix but i just can't figure out what the problem is because i don't fully understand how to implement a kinematic body. i believe the problem lies in this code kinematicBody.setLinearVelocity(0.0f, 1.0f);
because i get an error in "setLinearVelocity"
stating "The method setLinearVelocity(float, float) is undefined for the type BodyDef" i feel that i am doing something wrong here
Outcome i want: i want to be able to create a kinematic body that moves from point x to point y.
here is my relevant code:
package com.mohamed.JungleFighter;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.sun.xml.internal.ws.wsdl.writer.document.soap.Body;
public class JungleFighter extends Game {
World world = new World(new Vector2(0, -100), true);
Box2DDebugRenderer debugRenderer;
OrthographicCamera camera;
static final float STEP=1/60f;
static final int VELOCITYITERATIONS=6;
static final int POSITIONITERATIONS=2;
static final float WORLD_TO_BOX=0.01f;
static final float BOX_WORLD_TO=100f;
@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();
//test platform 3
BodyDef kinematicBody =new BodyDef();
kinematicBody.type = BodyType.KinematicBody;
kinematicBody.position.set(100, 250);
PolygonShape shape = new PolygonShape();
shape.setAsBox(50f, 25f);
fixtureDef.shape = shape;
fixtureDef.density = 0;
fixtureDef.friction = 0;
fixtureDef.restitution = 0;
kinematicBody.setLinearVelocity(0.0f, 1.0f);
// Create our body in the world using our body definition
world.createBody(kinematicBody).createFixture(shape, 50.0f);
shape.dispose();
debugRenderer = new Box2DDebugRenderer();
}
@Override
public void dispose() {
}
@Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
debugRenderer.render(world, camera.combined);
world.step(STEP, VELOCITYITERATIONS, POSITIONITERATIONS);
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}