my 2d tilemap prefab's center point is wrong.
so i am trying to make a roguelike dungeon game following this tutorial series: https://www.youtube.com/watch?v=qAf9axsyijY&t=0s
i encountered this problem where it seems that all the room prefabs have their center on the bottom left corner instead of the real center.
Mechanics explaination: Starting from the start room every door has a spawnpoint (red crystal) in the center of the next 10x10 grid square which has a script that spawnes in a compatible room which also has the spawnpoint(s) to repeat the process. The room's center should perfectly align with the spawnpoint.
to visualize my problem i took this code snippet and screenshots below:
code snippet of the spawn function inside the spawnpoint snippet
private void Spawn()
{
if (spawned == false)
{
switch (openingDirection)
{
case 1:
//spawn room with bottom door
rand = Random.Range(0, templates.bottomRooms.Length);
Instantiate(templates.bottomRooms[rand], transform.position, Quaternion.identity);
break;
case 2:
//spawn room with top door
rand = Random.Range(0, templates.topRooms.Length);
Instantiate(templates.topRooms[rand], transform.position, Quaternion.identity);
break;
case 3:
//spawn room with left door
rand = Random.Range(0, templates.leftRooms.Length);
Instantiate(templates.leftRooms[rand], transform.position, Quaternion.identity);
break;
case 4:
//spawn room with right door
rand = Random.Range(0, templates.rightRooms.Length);
Instantiate(templates.rightRooms[rand], transform.position, Quaternion.identity);
break;
default:
break;
}
spawned = true;
}
}
Answer by unity_KSMWJMK_cGKj5Q · May 02, 2020 at 01:28 PM
@rubenwinant You can change the Pivot ( the center) of your sprite in the Inspector.
Your answer
Follow this Question
Related Questions
How to use Shadow Caster 2D with Tilemap? 0 Answers
Problem with Strings updatings on Gui 0 Answers
How to use URP Shader Graph on a tilemap? 1 Answer
Creating a background to have a random shape destroy effect 0 Answers
,2d gameObject unwanted outline 0 Answers