### Attached Files

The following files have been attached to this tutorial:

.capx

### Stats

1,814 visits, 2,771 views

### Tools

Hello, welcome to this tutorial I want to show you how to create

an object that automatically changes the angle to rotate

this object and change its length so that it closely matches the

position where the mouse cursor is.

Come on then the following steps:

1. Create a sprite brand name object "o", you can choose any

name, in my case just chose the name letter "o", applied the color green,

you can apply any color to this object.

2. Add a Mouse type object in the project.

3. Okay now let's start coding. The guide EventSheet create four global variables

the type number, a name "a", another name "b", another name "c" and another

name "ang", which are the sides of a triangle and the the included angle respectively.

Note that the side "c" corresponds to the variation of the mouse in the X axis, the side "b"

corresponds to variation in the mouse Y-axis and "a" because it is the hypotenuse of a triangle

rectangle, "ang" corresponds to the internal angle of the triangle between the sides "b" and "c".

4.Na EventSheet guide create a System name of event -> Every tick and assign it the following

actions: set the following values ​​for the variables:

a = sqrt ((o.x-mouse.x) ^ 2 + (o.y-mouse.y) ^ 2)

b = sqrt ((o.y-mouse.y) ^ 2)

c = sqrt ((o.x-mouse.x) ^ 2)

and the length of the arrow sprite for the following commands:

o.set size = (sqrt (b ^ 2 + c ^ 2) -10 5)

size "o" is the type (o.width, o.heigth), in this case 5 high.

5. more added these following commands, even in the Event Sheet:

System -> Compare Two Values: mouse.y> = o.y

System -> Compare Two Values: mouse.x> = o.x

These events trigger the following action:

Sets the value of "ang" for: ang = (asin (b / (a)))

Now a few more commands:

System -> Compare Two Values: mouse.y <= o.y

System -> Compare Two Values: mouse.x> = o.x

These events trigger the following action:

Sets the value of "ang" for: ang = 360- (asin (b / (a)))

Other commands:

System -> Compare Two Values: mouse.y <= o.y

System -> Compare Two Values: mouse.x <= o.x

These events trigger the following action:

Sets the value of "ang" for: ang = -180+ (asin (b / (a)))

Finally these commands:

System -> Compare Two Values: mouse.y> = o.y

System -> Compare Two Values: mouse.x <= o.x

These events trigger the following action:

Sets the value of "ang" for: ang = -180- (asin (b / (a)))

Well, that's what I wanted to show, the result should look like the image below.

The code should look like the following below:

Thank you all.

.CAPX