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.