For my old game my game corrupted and I couldn’t seem to fix it so I moved on. For my new game that I am making I wanted to try to make it so that when A is pressed, It will find the closest sprite and that sprite would become the new player and you could take control, how would I do that?
This is the very very beta of this game and yes, I am using sprite utils.
Also don’t judge me that I do the art first.
Swappang {VERY BETA}
3 Likes
I would do something like:
SpriteDistance = 1000000
For (value) in [list of all sprites of kind (potentialPlayer)]:
Set Dist = (use Pythagorean theorem to find distance from the (current player) to (value))
If (Dist) < (SpriteDistance):
Set SpriteDistance to (Dist)
Set ClosestSprite to (value)
After it loops through all the sprites, ClosestSprite will be the closest sprite to the player!
If the current player is the same sprite type as the potential players, you might have to add a check that Dist =/= 0 so that your closest player won’t be the player you’re currently controlling.
Hope this helps! (I also hope you can read my horrible sudo code lol)
If you need help with the Pythagorean theorem just ask!
1 Like
Thank you, twice!
1 Like
So I tried using what you said and I am having some errors and I can’t find out what is causing them, can you help me with this?
Swappang