(Redirected from Point Towards Mouse-Pointer)

 Point Towards () `point towards ( v)` Category Motion Type Stack

The Point Towards () block is a motion block and a Stack block that points its sprite towards the mouse-pointer or the costume center of another sprite.

## Example Uses

The Point in Direction () block does not point sprites at specific objects; the Point Towards () block, however, can point sprites at other sprites or the mouse pointer.

Some common uses for the Point Towards () block:

• Continuously making a sprite point towards the mouse
```when gf clicked
forever
point towards (mouse-pointer v)
move (10) steps
```
• Guiding a sprite on where to move
```point towards (Sprite2 v)
repeat until <touching (Sprite2 v)?>
move (5) steps
```
• Pointing towards a goal in the project
```when I receive [Hint v]
point towards (Treasure v)
```

## Workaround

Main article: List of Block Workarounds

This block can be replicated with the following code, which uses trigonometry:

```set [delta_x v] to (([x position v] of (sprite 1 v)) - (x position))
set [delta_y v] to (([y position v] of (sprite 1 v)) - (y position))
if <(delta_y) = > then
if <(delta_x) < > then
point in direction (-90)
else
point in direction (90)
end
else
if <(delta_y) < > then
point in direction ((180) + ([atan v] of ((delta_x) / (delta_y))))
else
point in direction ([atan v] of ((delta_x) / (delta_y)))
end
end
```

However, this requires more code and decreases its readability.

## Related Suggestion

A related block has been asked for by Scratchers: `point towards x: (0) y: (0)::motion`
It would be used to point the sprite at a specific pixel.

This can be done by placing a sprite at that location and using the Point Towards () block or by using this code:

```define point towards x:(x) y:(y)
set [delta_x v] to ((x) - (x position))
set [delta_y v] to ((y) - (y position))
if <(delta_y) = > then
if <(delta_x) < > then
point in direction (-90)
else
point in direction (90)
end
else
if <(delta_y) < > then
point in direction ((180) + ([atan v] of ((delta_x) / (delta_y))))
else
point in direction ([atan v] of ((delta_x) / (delta_y)))
end
end
```

And then

```point towards x:() y:() :: custom
```

A copy of this code may be obtained here.

### Example Uses

```when gf clicked
point towards x:(x) y:(y) :: custom
```

or

```when I receive [turn v]
point towards x:(x) y:(y) :: custom
```