Discuss Scratch

M1LK_yes
Scratcher
94 posts

Arrow Pointer

I'm making a survivor-type game and I'm trying to make an arrow point to the closest chest. The problem is that I'm using clones for the chest and the actual chest sprite is hidden. How do i fix this?
legendary34678
Scratcher
1000+ posts

Arrow Pointer

You can store the positions of the chests in lists (one for x and one for y). Then, you would calculate the distance to each chest with the distance formula. Finally, you would figure out the shortest distance and determine which chest the distance corresponds to.

After you know which chest is the closest, you can use trigonometry to point towards the specific x and y coordinates like so:

point in direction (([atan v] of (((x) - (x position)) / ((y) - (y position)))) + ((180) * <((y) - (y position)) < (0)>))

Last edited by legendary34678 (June 21, 2023 19:23:54)

M1LK_yes
Scratcher
94 posts

Arrow Pointer

So I followed the code but now it points in a direction thats not even close to the chests. Also, lets say a chest is to the left of you. Now if you were moving down, you would expect the arrow to slowly point upwards, but that doesn't happen with my project. Im not sure what im doing wrong so i still need help ;-;
09878901234321
Scratcher
500+ posts

Arrow Pointer

Can you link to the project so that we can see the issue with your code? Make sure it's shared.
M1LK_yes
Scratcher
94 posts

Arrow Pointer

The Arrow is in the Sprite of “Waypoint Marker” which is all the way at the bottom. https://scratch.mit.edu/projects/867210688/editor/
09878901234321
Scratcher
500+ posts

Arrow Pointer

Since this is a scrolling game, you have to account for the player's position. This code should work:

Last edited by 09878901234321 (June 21, 2023 23:00:10)

M1LK_yes
Scratcher
94 posts

Arrow Pointer

Thanks guys, It finally worked. BIG THANK YOU!!! ))))))

Powered by DjangoBB