Trouble with movement of enitities at an angle [SOLVED]

(Granit Bajraktari) #1

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;
		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) {;
		if (collide("enemy", x, y)) {
			graphic = bulletExplosionAnimation;"explode");
	private function destroy():void {;
	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
		return angle;


I also tried with the other way with trigonometry but that doesn’t work either. (It works but it shoots sideways)

(Zachary Lewis) #2

If the angle is off by 90°, have you tried adjusting the angle during update()?


var v:Point = new Point();
FP.angleXY(v, angle - 90, speed);


(Granit Bajraktari) #3

Yes , you’re right , thanks.

But that way it goes backwards Should be like this.

var v:Point = new Point(); FP.angleXY(v, angle + 90, speed);

Basically just + instead of - .

Still wondering why it’s offsetted by 90°.

And why I can’t get a paragraph without separating the lines by one empty line.

(Zachary Lewis) #4

It is just a quirk of the engine. When Chevy Ray wrote it, he based it off GameMaker (which also does angles weird). Something about the axes being swapped or flipped or something.

Discourse uses GitHub-flavored Markdown, which requires two line-returns for a paragraph. One of the goals of Markdown was to make something that was readable when formatted as plain text and enhanced when parsed.

(Granit Bajraktari) #5

Well that makes sense. Thanks.