0

I am trying to have my player land on a tile and if it lands on that tile place a new tile to the side of the tile you land on. Currently how I have it, it will place the new tile on the first starting one.I added a photo to help make sense of what im trying to achieve. The white cube is the player and I want that red tile to the left of the blue to be to the left of the one I am on.Instantiate(mutatedTile, new Vector3(-2, 0, 0), Quaternion.identity); Picture showing screen

Chris
  • 59
  • 1
  • 3
  • There are a lot of tutorials on detecting where hits/collisions were. Try finding one as it covers wht you need – BugFinder Aug 08 '21 at 22:05

1 Answers1

0

Suppose that one tile occupies one unit, then if you want, for example, to place a tile:

To the left of the player:

tile.position = new Vector3(Mathf.RoundToInt(player.position.x) - 1, player.position.y, player.position.z);

In front of the player:

tile.position = new Vector3(player.position.x, player.position.y, Math.RoundToInt(player.position.z) - 1);

In this way, the tiles are placed on an abstract grid with integer coordinates.

P.S.: If your tile occupies more than one unit, then you need to round it with a certain step. For example, if your tile is 10x10 in size, then it is necessary that the coordinates are a multiple of 10. If you need a function for rounding in increments, then you can ask - I'll throw it off.

I hope I came up with an idea.

Yili
  • 11
  • 3
  • This seems like it would definitely work but I am very new to this.. I am not sure how I would go about actually adding this in. – Chris Aug 08 '21 at 20:02
  • Try to do this after creating the tile: var tile = Instantiate(Object); tile.transform.position = new Vector3(Mathf.RoundToInt(player.position.x) - 1, player.position.y, player.position.z); Where "player" is the Transform of the cube. – Yili Aug 09 '21 at 05:25
  • `In front of the player` should be `z + 1` not `- 1` ;) – derHugo Aug 09 '21 at 06:28
  • It depends on what is the front for the camera. And besides, there is not much difference, anyone has enough brains to change "-" from"+". – Yili Aug 09 '21 at 15:29