hi guys, i have a problem, i don’t can do my spaceship shooting with mouse, my spaceship rotation changes with mouse cursor, but i dont can changes my shot direction.
my spaceship and my fire ball extends Sprite [box2d]
the space ship look in mouse cursor direction.
my method Fire, stay in my spaceship class
public void fire(){
fireballs.add(new FireBall(screen, corpo.getPosition().x, corpo.getPosition().y));
}
My method constructor and defineFireBall,stay in my fireball class
public FireBall(PlayScreen screen, float x, float y){
super(screen.getAtlas().findRegion("fireball"));
this.screen = screen;
this.world = screen.mundo;
frames = new Array<TextureRegion>();
setBounds(x, y, 6 / ExGame.PPM, 6 /ExGame.PPM);
defineFireBall();
}
public void defineFireBall(){
BodyDef bdef = new BodyDef();
bdef.position.set(getX(), getY());
bdef.type = BodyDef.BodyType.DynamicBody;
if(!world.isLocked())
b2body = world.createBody(bdef);
FixtureDef fdef = new FixtureDef();
CircleShape shape = new CircleShape();
shape.setRadius(3 / ExGame.PPM);
fdef.shape = shape;
fdef.restitution = 1;
fdef.friction = 0;
b2body.createFixture(fdef).setUserData(this);
b2body.setLinearVelocity(new Vector2( 2, 2.5f));
setOriginCenter();
setRotation(screen.jogador.getRotation());
}
my update method
public void update(float dt){
stateTime += dt;
setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - getHeight() / 2);
if((stateTime > 3 || setToDestroy) && !destroyed) {
world.destroyBody(b2body);
destroyed = true;
}
if(b2body.getLinearVelocity().y > 2f)
b2body.setLinearVelocity(b2body.getLinearVelocity().x, 2f);
if((b2body.getLinearVelocity().x < 0))
setToDestroy();
}
If you can help me, I thank you.