# How to move half-way to where mouse clicked?

**URL:** https://forum.kirupa.com/t/how-to-move-half-way-to-where-mouse-clicked/270080
**Category:** flash
**Created:** [September 4, 2008, 11:10pm UTC](https://forum.kirupa.com/t/how-to-move-half-way-to-where-mouse-clicked/270080 "2008-09-04T23:10:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![th3Phallex](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@th3Phallex](https://forum.kirupa.com/u/th3Phallex)
#### Post date: [September 4, 2008, 11:10pm UTC](https://forum.kirupa.com/t/how-to-move-half-way-to-where-mouse-clicked/270080/1 "2008-09-04T23:10:32Z")

</div>

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:

```auto

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:

```auto

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:
