# AS - movement after mouse (x and rotate)

**URL:** https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015
**Category:** flash
**Created:** [July 27, 2004, 8:16pm UTC](https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015 "2004-07-27T20:16:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![abraxas](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@abraxas](https://forum.kirupa.com/u/abraxas)
#### Post date: [July 27, 2004, 8:16pm UTC](https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015/1 "2004-07-27T20:16:44Z")

</div>

Hello!

I want to have a ball, that will follow the mouse a little… The ball will only follow the x way but i cant get it working. I have this code on the frame:

this.onEnterFrame=function(){  
controlX=\_xmouse\*2-(x1+x2)/2;  
move();{  
\_root.ball(controlX, 176.8)  
}  
}

I have no idea if this one is right in anyway… but no error atleast.  
The ball have the instance name “ball”.

I also want that the ball will rotate how longer it is at the x way, so it will rotate as much as \_xmouse.  
Can someone change the code so it will work?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 8:36pm UTC](https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015/2 "2004-07-27T20:36:38Z")

</div>

try this:

ball.onMouseMove = function() {  
this.\_x = \_xmouse/2; //2 is how much you want it to follow by  
this.\_rotation = \_xmouse;  
}

try that, lemme know how it works.

:p:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 28, 2004, 12:03am UTC](https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015/3 "2004-07-28T00:03:04Z")

</div>

> [@bodyvisual](#):
>
> try this:
> 
> ball.onMouseMove = function() {  
> this.\_x = \_xmouse/2; //2 is how much you want it to follow by  
> this.\_rotation = \_xmouse;  
> }
> 
> try that, lemme know how it works.
> 
> :p:

Thanks ! 😃

it works great, i only needed to change one thing on the mc 🙂

This is my code now

ball.onMouseMove = function() {  
this.\_x = \_xmouse/4;  
this.\_rotation = 1.2\*\_xmouse;  
}

but… the ball start on x=0… can i do anything to change that? And is it hard to add so the ball smoothly will stop?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 28, 2004, 2:47am UTC](https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015/4 "2004-07-28T02:47:52Z")

</div>

right before the first line do this:

ball.\_x = 30; //30 is your x position.

if you want to have it on a certain y, put this, as well as the above:

ball.\_y = 30; //30 is your y position.

hope that helps ya!

:p:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 1, 2004, 3:02pm UTC](https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015/5 "2004-08-01T15:02:43Z")

</div>

> [@bodyvisual](#):
>
> right before the first line do this:
> 
> ball.\_x = 30; //30 is your x position.
> 
> if you want to have it on a certain y, put this, as well as the above:
> 
> ball.\_y = 30; //30 is your y position.
> 
> hope that helps ya!
> 
> :p:

hm… it dont work ☹ It is on X=0 yet ☹

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 1, 2004, 3:15pm UTC](https://forum.kirupa.com/t/as-movement-after-mouse-x-and-rotate/59015/6 "2004-08-01T15:15:37Z")

</div>

i got it working 😃 😃 😃

i had to do this:

this.\_x = 243.8+\_xmouse/4;

now it works 😃

But can someone tell me how to do it so it will smoothly stop ?
