# Elastic Rotation

**URL:** <https://forum.kirupa.com/t/elastic-rotation/297444>\
**Category:** flash\
**Created:** [October 2, 2009, 5:33am UTC](https://forum.kirupa.com/t/elastic-rotation/297444 "2009-10-02T05:33:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jallouf](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jallouf](https://forum.kirupa.com/u/jallouf)\
**Post date:** [October 2, 2009, 5:33am UTC](https://forum.kirupa.com/t/elastic-rotation/297444/1 "2009-10-02T05:33:53Z")

</div>

I have proper code to make objects rotate on an axis adjacent to the mouse.  
I also have proper code on how to make objects elastically bounce towards a specific x,y coordinate.

So far the code I have is for the object to follow the mouse when clicked. when the mouse is up, the objects (on a rotational axis) wind back to original position.

What I would like to do, is combine the formulas for rotation with the elastic formulas to bounce these objects back into place with rotational movement.

Here is the code so far:

```auto

rams.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);

function onLoop(event:Event):void {
	var dx:Number = mouseX - rams.x;
	var dy:Number = mouseY - (rams.y + 230);
	var radians:Number = Math.atan2(dy, dx);
	rams.rotation = radians * 180/Math.PI;
}

function onReleas(event:Event):void {
	var ex:Number = 1000 - rams.x;
	var ey:Number = 370 - rams.y;
	var radians:Number = Math.atan2(ey, ex);
	rams.rotation = radians * 180/Math.PI;
}

function mousedown(event:MouseEvent):void {
	rams.removeEventListener(Event.ENTER_FRAME, onReleas);
	rams.addEventListener(MouseEvent.MOUSE_UP, mouseup);
	rams.addEventListener(Event.ENTER_FRAME, onLoop);	
}

function mouseup(event:MouseEvent):void {
	rams.removeEventListener(Event.ENTER_FRAME, onLoop);
	rams.removeEventListener(MouseEvent.MOUSE_UP, mouseup);
	rams.addEventListener(Event.ENTER_FRAME, onReleas);
}

```

If anybody has any tips that would be much appreciated.
