Manually snap to middle

Hi, I don’t get the idea of why Sir Rick manually changes the position of the cactus on the grid, and how it settled In the middle by making it a child of an empty object. Need a bit of guidance in this and also my cactus not set in the middle even after applying this method.

Hi Daniyal,

The position of a child game object is always relative to its parent. We set the parent game object to the desired position on our grid. If the child, which has got the SpriteRenderer component attached, is not centred on the tile, we slightly move it.

Did this clear it up for you?

Hi Nina,

Thanks for your response but I am still confused.

Have you already rewatched the video at least one more time?

Yes ma’am I have rewatched it a few times. I am pretty much understand what you were said the thing which I am not understand is that why we can’t set the position of the cactus without break it into parent-child why we need to make it a child object to settle the position of it? Sir rick said at 05:15 that the position is not gonna change when we drop it into prefab.Why is that?

There is something called pivot point in computer graphics. Everything is rendered relative to that point. In Unity, we cannot change the pivot point. Or rather: We would have to do that via code, and it is fairly difficult. For this reason, we move the child relative to the parent.

We do that because we have a problem to solve: Adjusting the position of our sprite within the tile. If you are happy with the position of your cactus, there is no need to create a child.

1 Like

Wish I got teachers like you in university :pray: Thank you :slightly_smiling_face:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms