#Object & Transform Rotating

1 messages · Page 1 of 1 (latest)

ionic vigil
#

Hi, basically I have an empty object which only includes a transform component and I'm trying to rotate it 90 degrees so it can instantiate objects with a tilt.
But the rotation doesn't work for me.

The actual empty object is already in the game and I tried changing it both manually and via the code but it didn't work.
Any ideas how to rotate it?

This is the current situation, and I want the tiles to spawn correctly on the blue player stand like the black one with the 90 degree tilt.

The spawn point object is set at the top right corner of the blue player stand. (from current POV)

glossy cliff
#

you know you can define the objects rotation when you instantiate it

#

Instantiate(Object, position, rotation)

#

if you dont want to deal with quaternions you can use EulerAngle

ionic vigil
#
 void SpawnTiles(GameObject player, float playerNum)
    {
        Transform playerSpawn = player.GetComponent<Player>().spawnPosition;
        //Debug.Log(playerSpawn.transform.rotation.y);
        Vector3 position = playerSpawn.position;
        int i = 1;

        for (; i <= playerTileCount / 2; i++, playerSpawn.position = position)
        {
            GameObject gameTile = Instantiate(pile.Pop().CreateTile(tile), playerSpawn.position,  Quaternion.Euler(90, playerNum * 90, 0)) as GameObject;
            gameTile.name = "Tile" + i + "P" + playerNum;
            gameTile.transform.SetParent(player.transform);
            
            position.x += 28;
            gameTile.transform.localPosition = playerSpawn.position;
        }
        
        position.x -= 28;
        position.z -= 35;
        playerSpawn.position = position;

        for (; i <= playerTileCount; i++, playerSpawn.position = position)
        {
            GameObject gameTile = Instantiate(pile.Pop().CreateTile(tile), playerSpawn.position,  Quaternion.Euler(90, playerNum * 90, 0)) as GameObject;
            gameTile.name = "Tile" + i + "P" + playerNum;
            gameTile.transform.SetParent(player.transform);
            //gameTile.transform.localPosition = position;
            //gameTile.transform.localPosition = playerSpawn.position;
            position.x -= 28;
            
        }
    }

This is the function that spawns them into the game.

coarse portal
#

I don't have the time to dig into this, but off the top, you shouldn't need to rely on the rotation of the tiles to position the tiles along the player's side. Those are independent of each other. Start with just getting the tiles lining up correctly.

#

You should consider:

#
  1. Using two for loops, nested inside each other, which iterates over the number of rows and columns to place the tiles at.

  2. Determine the starting tile position, spawn a tile at that position, and then spawn the next at an offset based on the current row/col count of the for loops

  3. Determine which axis to start along ( x or y), which will change the offset axis you move along

#

It's easier said than done, there's a lot of complex logic you have to handle here.

#

If it's too difficult, you can always just manually place empty game objects as containers, store those in a list, and spawn the tiles at each of those positions.

ionic vigil
#

The rotation is just so it'll fit the POV of the current player.

1 & 2) I change the offset of the starting position with the position.x +/-= 28and for the first player it works, but it doesn't seem to change the axis it spawns at for the next player,
even though the rotation of the starting point works.

coarse portal
#

I understand the rotation is to make the tiles look like they're facing the player, but again, that's irrelevant to actually placing the tiles.

#

Get the placement working first, then you can just rotate the tiles to face the way they need.

ionic vigil
#

I don't think the rotation is relevant to the position since it seems to be fine, it's just the position that's the issue.

For 2 and 3, I already configured it, the selected object is the starting position for the spawning, and it should get a positive offset towards the X axis (red arrow) as it's been rotated.

coarse portal
#

Right, I did say the rotation is irrelevant (not relevant) to the position.

#

Are these tiles children of the player's mat?