Need Some Math Help Please

30 views
Skip to first unread message

xhunterko

unread,
Feb 18, 2016, 1:22:53 AM2/18/16
to HaxeFlixel
So I'm fiddling with my weapon code and I have it set to where you hold down the key and it circles the player. Which is nice and an attack I want. However, I noticed that when I told it to justPress a key, the weapon did not circle. Instead, it exhibited a yo yo like behavior. I thought nothing of it until I wanted another attack, which is just that. However, it yo yos in a random direction each time, and I want it to simply yo yo in one of the cardinal directions depending on where the character is facing.

So how do I do that mathematically?

This is what I'm doing so far:

if (FlxG.keys.justPressed.C)
       
{
            stretchingHook
();
            stretching
= true;
           
            radius
= 0;
            ang
= 0;            
       
} else
       
{
            followPlayer
();
            ang
= 48;
            radius
= 0;
       
}
       
       
if (FlxG.keys.pressed.Z        
           
#if !FLX_NO_GAMEPAD
           
#if OUYA
           
|| gamepad.pressed(OUYAButtonID.U))
           
#else
           
|| gamepad.pressed(XboxButtonID.X))
           
#end
           
#else) #end
       
{
           
            radius
= 48;
            ang
= 0;
           
            circlePlayer
();
            circliing
= true;
       
}
       
else
       
{    
           
            followPlayer
();
       
}

circlePlayer

   
private function circlePlayer(Acceleration:Float = 4):Void
   
{    
        circliing
= true;
       
this.x = _player.x + radius * Math.cos(ang);
       
this.y = _player.y + radius * Math.sin(ang);
        ang
+= speed * FlxG.elapsed; //you can multiply this to FlxG.elapsed to have a constant velocity
       
//you can reset ang to 0 whent it i over than 360
       
   
}

stretchingHook is the same as circlePlayer except on call.

So how can I get it to act like a yo yo?

Using 3.x.x.

Sam Bellman

unread,
Feb 18, 2016, 3:47:56 AM2/18/16
to HaxeFlixel
Just modify your circlePlayer function so that it's the radius that changes and ang is  where the player is facing. 

xhunterko

unread,
Feb 18, 2016, 7:54:39 AM2/18/16
to HaxeFlixel
That worked! Thanks! ^^
Reply all
Reply to author
Forward
0 new messages