Author Topic: FlxWeapon shooting with offset  (Read 1571 times)

athis

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
FlxWeapon shooting with offset
« on: Sat, May 9, 2015 »
Hello, I've just started fiddling with FlxWeapon class and encountered a problem.
When I try to shoot at the mouse, bullets are moving considering their origin in top-left corner.
I would like to make them move, so they aim with their center, is it possible in any efficient way?

A visualization for you (disregard turret angle):
What is going on:

How it should look:


I hope my problem is understandable, basically it's just making sure that my bullet passes mouse coords with middle point, not top-left corner.

Code that I'm using for it
Code: [Select]

                player = new FlxSprite(160, 200, Reg.TURRET.path);
 
lazer = new FlxWeapon("lazer", player);
lazer.makeAnimatedBullet(50, Reg.TURRETBULLET.path, Reg.TURRETBULLET.width, Reg.TURRETBULLET.height, [1], 0, true, 0, 0);
lazer.setFireRate(100);
lazer.setBulletSpeed(200);

lazer.group.forEach(function(_b:FlxBullet) { _b.origin.set(_b.width/2, _b.height/2); } );
add(player);
add(lazer.group);

Thank you.
« Last Edit: Sat, May 9, 2015 by athis »

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: FlxWeapon shooting with offset
« Reply #1 on: Sun, May 10, 2015 »
Would you mind posting the FlxWeapon code? I don't use power tools.

athis

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: FlxWeapon shooting with offset
« Reply #2 on: Sun, May 10, 2015 »
Sure, but it is so long that I used offsite for it:
http://ctrlv.it/haxe/976/1936714006

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: FlxWeapon shooting with offset
« Reply #3 on: Sun, May 10, 2015 »
Ok, I'm not seeing how you are firing it with your code and like I said I haven't used powertools. Maybe try using the "fireatposition" function instead? You could then set the X/Y equal to the mouse coordinates, but with whatever offsets you want.

Maybe it would look something like:

lazer.currentBullet.fireAtPosition(_player.x+_player.width/2, _player.y+_player.height/2, FlxG.mouse.cursor.x+10, FlxG.mouse.cursor.y+10, 200);