Circle Movement

268 views
Skip to first unread message

xhunterko

unread,
Sep 2, 2015, 9:23:07 AM9/2/15
to HaxeFlixel
Okay, I've googled about an hour or so now and I can't seem to find something satisfactory. And I KNOW I've seen this before on this forum or in a repository but I can't remember where exactly. So, what I'm looking for is:

How do I get one sprite to orbit/circle around another sprite?

Something with FlxTween would be fine I think, but I'm more looking for something done without the tween. What I want it to do, is have it circle tightly around a sprite, then circle outward as the mouse is held down. And I'm not sure if I can do that with FlxTween.

Any help?

Adriano Lima

unread,
Sep 2, 2015, 10:05:44 AM9/2/15
to HaxeFlixel
I think you want something like this...

var radius:Int = 100;//circle radius
var ang:Float = 0;
var speed:Float = 0.5;

function update():Void {
   obj2.x = obj1.x + radius * Math.cos(ang);
   obj2.y = obj1.y + radius * Math.sin(ang);
   ang += speed;//you can multiply this to FlxG.elapsed to a constant velocity
   //you can reset ang to 0 when it is over than 360

xhunterko

unread,
Sep 2, 2015, 8:32:47 PM9/2/15
to HaxeFlixel
Well, that works, thanks! Buuuuuut the collisions are now broke.

I am doing this:

override public function update():Void
{

//etc
///
//Hitting Mob
       
//FlxG.overlap(ChainGun.group, enemyGroup, playerHitEnemy);    
       
FlxG.collide(PlayerChainBall, enemyGroup,playerHitEnemy);    
       
FlxG.collide(PlayerChainBall, enemyGroup);
       

       
//Checking to see if pixel perfect collisions would change anything
       
for (obj in enemyGroup.members)
           
{
               
if (FlxG.pixelPerfectOverlap(PlayerChainBall, obj))
               
{
                   
FlxG.collide(PlayerChainBall, enemyGroup,playerHitEnemy);    
               
}
           
}

//etc
super.update();

}

///etc

/////

//Enemy getting hit by player bullet
   
private function playerHitEnemy(playerBullet:FlxObject, enemy:SlimeClasses):Void
   
{    
       
FlxG.sound.play("Splat", 0.95);
       
        enemy
.health -= 1;        
        enemy
.bonked = true;
       
       
if (enemy.health <= 0)
       
{
            particleEmitter
.x = enemy.x + 8;
            particleEmitter
.y = enemy.y + 8;
           
var i:Int;
           
for (i in 0...10) {
               
var particle:FlxParticle = new FlxParticle();
                particle
.makeGraphic(2, 2, FlxColor.RED);
                particle
.visible = false;
                particleEmitter
.add(particle);
           
}
            particleEmitter
.start(true, 2, 0, 10, 1);
           
           
           
           
//if (enemy.SlimeClass == 0) money += 4;
           
//if (enemy.SlimeClass == 1) money += 16;
           
//if (enemy.SlimeClass == 2) money += 80;
           
            enemy
.kill();
            enemyGroup
.remove(enemy, true);
       
}
   
}

And I am getting this:

http://www.newgrounds.com/dump/item/5f2307098deab007b37e0fce55063e29

Anyone have any ideas on how to improve collisions here?

xhunterko

unread,
Sep 3, 2015, 8:37:28 AM9/3/15
to HaxeFlixel
I solved the issue using overlap instead of collision. Thanks again for your help!
Reply all
Reply to author
Forward
0 new messages