How to Align Gun with Bullets
Posted
by
Shane
on Game Development
See other posts from Game Development
or by Shane
Published on 2012-07-28T15:26:24Z
Indexed on
2012/10/07
3:53 UTC
Read the original article
Hit count: 313
I have a top-down 2D shooter. I have an image of a player holding a gun, that rotates to face the mouse. Please note that the gun isn't a separate image tethered to the player, but rather part of the player. Right now, bullets are created at the player's x and y. This works when the player is facing the right way, but not when they rotate. The bullets move in the right direction, but don't come from the gun. How can I fix this?
TL;DR: When the player rotates, bullets don't come from gun.
public void fire() {
angle = sprite.getRotation();
System.out.println(angle);
x = sprite.getX();
y = sprite.getY();
Bullet b = new Bullet(x, y, angle);
Utils.world.addBullet(b);
}
© Game Development or respective owner