Here’s the deal. I want to move my bullet entity along an angle. But the problem is that when I shoot, the bullets go sideways. The spread is how I want it , but the direction is wrong by about 90°.
Here’s my code:
`public class Bullet extends Entity {
[Embed(source = "../assets/Bullet.png")]
private const IMAGE:Class;
[Embed(source = "../assets/BulletAnimation.png")]
private const EXPLOSION_ANIM:Class;
private var bulletImage:Image;
private var bulletExplosionAnimation:Spritemap;
private var speed:Number;
private var angle:Number;
public function Bullet(posx:int, posy:int) {
bulletImage = new Image(IMAGE);
bulletExplosionAnimation = new Spritemap(EXPLOSION_ANIM, 6, 6, destroy);
speed = 300;
angle = getAngle();
graphic = bulletImage;
setHitboxTo(graphic);
setOrigin(width, height);
x = posx;
y = posy;
bulletImage.angle = angle;
type = "bullet";
bulletExplosionAnimation.add("explode", [0, 1, 2], 0.2, false);
bulletExplosionAnimation.scale = 1.25;
}
override public function update():void {
if (graphic == bulletImage) {
var v:Point = new Point();
FP.angleXY(v, angle, speed);
x += v.x * FP.elapsed;
y += v.y * FP.elapsed;
}
else if (graphic == bulletExplosionAnimation) {
setHitbox(0, 0, -1000, -1000); //Dirty hack to get the hitbox out of the way
}
if (y < 0) {
FP.world.remove(this);
}
if (collide("enemy", x, y)) {
graphic = bulletExplosionAnimation;
bulletExplosionAnimation.play("explode");
}
}
private function destroy():void {
FP.world.remove(this);
}
private function getAngle():Number {
var angle:Number;
var negativityDeterminant:int; //This will decide if the angle remains the same or if it will become negative
negativityDeterminant = FP.rand(2); //Get random number either 1 or 0
angle = FP.random; //Get random number from 0.00000000000001 to 1;
angle = angle * 10;
if (negativityDeterminant == 1) {
angle = -(angle); //If the negativityDeterminant is 0 , the angle remains unchanged , if it's 1 it will become negative
}
trace(angle);
return angle;
}
}
`
I also tried with the other way with trigonometry but that doesn’t work either. (It works but it shoots sideways)