Hey everyone, I’ve got a (hopefully) simple question, and I’m no trig master so I was hoping someone can suggest a solution.
Let’s say I have a function that acts like a ‘charge-up’ power bar… when you click, it increases a variable on ENTER_FRAME until you let go:
var charge:Number = 0;
function Start():void {
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDn);
}
function mouseDn(event:MouseEvent):void{
stage.addEventListener(Event.ENTER_FRAME, startCharge);
stage.addEventListener(MouseEvent.MOUSE_UP, stopCharge);
}
function startCharge(event:Event):void {
if (charge<100) {
charge ++;
powerBar.msk.height = charge;
//trace(charge);
} else {
charge = 100;
//trace("100%");
stage.removeEventListener(Event.ENTER_FRAME, startCharge);
}
}
function stopCharge(event:MouseEvent):void {
charge = 0;
stage.removeEventListener(Event.ENTER_FRAME, startCharge);
stage.removeEventListener(MouseEvent.MOUSE_UP, stopCharge);
}
Start();
What I’d like to do is use this “charge” variable, so when I release the mouse it will use this function:
function moveToClick(event:MouseEvent):void {
// create target area
var targetClickX:Number = mouseX;
var targetClickY:Number = mouseY;
var newTargetX:Number = targetClickX*(charge*.01);
var newTargetY:Number = targetClickY*(charge*.01);
trace("TargetX: "+newTargetX);
trace("TargetY: "+newTargetY);
// move to target
xMovement = new Tween(circleMC, "x", Back.easeIn, circleMC.x, targetClickX, 1, true);
yMovement = new Tween(circleMC, "y", Back.easeIn, circleMC.y, targetClickY, 1, true);
}
This function moves an MC to where you clicked on the stage.
My basic idea is that I want to specify a ‘max distance’ the “circleMC” can travel, and use the ‘charge’ variable to determine how far the MC will go in the direction of the mouseclick… 100% power will go the ‘max distance’ in the direction you clicked, 50% will only go half the max distance.
So I’m asking:
How can I create a “maximum distance” that the MC can go towards a point (i don’t want it to just go wherever you click), and how can I shorten this distance based on the ‘charge’ variable?
Please help!
BONUS
Also, using the trajectory of pointing at the mouse and the power from the powerBar, how can I make a random Wind direction that will alter the MC’s normal path?
THANK YOU IN ADVANCE! You guys are the best!
:beam: