Eng:Point Towards () (block)

The Point Towards  block is a Motion block and a Stack block. The block points its sprite towards the mouse-pointer or another sprite depending on its costume center; this changes the sprite's direction and rotates the 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: when gf clicked forever point towards [mouse-pointer v]  move (10) steps point towards [Sprite2 v] repeat until  move (5) steps when I receive [Hint v] point towards [Treasure v]
 * Continuously making a sprite point towards the mouse
 * Guiding a sprite on where to move
 * Pointing towards a goal in the project

Workaround
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) = [0]> then if <(delta_x) < [0]> then point in direction (-90 v) else point in direction (90 v) end else if <(delta_y) < [0]> 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

Related Suggestion
A related block has been asked for by Scratchers: point towards x: (0) y: (0) // category=motion

It would be used to point the sprite at a specific pixel.

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

set [delta_x v] to ((x) - (x position)) set [delta_y v] to ((y) - (y position)) if <(delta_y) = [0]> then if <(delta_x) < [0]> then point in direction (-90 v) else point in direction (90 v) end else if <(delta_y) < [0]> 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

The (x) and (y) variables are equivalent to the parameters.