Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to detect a nearby part on a certain axis?

I am going to make a script that restricts movement to the position of tiles, and the character cannot move again until the WalkToPoint (the tile's position) is reached. However, how would I be able to check if there is another tile in the direction that the player is trying to walk to?

Logic example:

if there is a tile located (5,0,0) from the current tile then
	-- Move player to tile
elseif there is a tile located (0,0,5) from the current tile instead then
	-- Move player to this tile instead
else
	wait()
end

3 comments

0

Pokemon Mystery Dungeon or a different tile-based game? Just wondering because I've done this before.

0

Mystery Dungeon, actually.

0

Guess this is a competition, as I'm working on making mine the equivalent of Brock Bronze ;)

1 answer

Just assume bounds. Put all your tiles into a two dimensional table representing the grid, and then use that to check.

if grid[posx+1][posy] then -- If one to the right

elseif grid[posx][posy+1] then -- If one forwards
 -- etc
end

2 comments

0

Could you be just a little bit more specific with your example code? I understand multidimensional tables, but I don't know how to reference the positioning along with that.

0

That assumes that posx and posy are your character's relative grid positions, and that you're tracking it. grid is assumed to be a multidimensional array storing cell data in an [x][y] format.

This discussion is preserved as it was. New answers, comments, and votes are closed.