Hello and welcome to another episode in the Godot basics tutorial series. In this episode we will be taking a look at Godot's version of a pivot point which is called an offset now a pivot point as a reference point for positioning rotating and scaling a game object. This reference point will come in a pair of value that represents both the x and y values in a X and Y coordinate system. The easiest way to think of a pivot point is just the reference point
At which our transform portion of our node object will get affected at and of course offset is the name the Godot uses to refer to the pivot point. Now
Now let's take a look at a basic example of our offset. Now I have here a sprite image a blue pikachu. However you'll notice that at the center you can see our reference point or offset reference point. And lucky for us could do is kind enough to set our offset value into the middle of our sprite image. In this case our offset value is zero on zero. One cool thing about the offset is that even when we change our sprite image it will not affect our offset.
So let's move our peek at you and notice how our picture moves in relation to our offset however are offset.
Value does not change and if we decide to move our offset value again which is our reference point that controls our game object.
Notice how our game object moves with the offset point and still retains its position in relation to our offset value.
In this case are offset value is now two hundred and one hundred. This value is not an accurate depiction of where it is but I wanted to keep the values straight forward.
Moving on let's go ahead and move our peak at you back to being centered with the offset value. One thing to keep in mind again is that our offset value is where our position our rotation and our scaling will change in relation to so let's go ahead and show you what happens when we spin our image.
While the offset is centered to our sprite
now as you can see here are sprite just rotated 360 degrees and it rotated the way it did because our offset value is in the center.
Now let's go ahead and rotate our value with our object or rather our offset value at the top left corner of our sprite image.
And as you can see here if we decide to rotate our value 360 degrees you'll notice that our sprite image rotates a little differently. And so for that reason alone it is generally best to keep your offset value centered to your sprite image. The reason we want to keep our sprite image is offset value in the center is because again if you don't are in this case our game object may behave differently than we would expect it to. I want to add another reason why we want to keep our offset value center to our image and that is when we want to calculate for boundary limits.
For example if we choose to move our picture right and left the formula for calculating that will be simple compared to if we chose our offset to be anywhere else outside of the center. One cool thing about Godot is that even though it gives us an offset value in reality could those 2D system is very close to a skeletal animation program. Another word for skeletal animation is rigging now skeletal animation is a technique in computer animation which a character is represented in two parts a surface representation used to draw the character and a higher key.
Keep that word in mind a hierarchy set of interconnected parts which we call bones and our representation of characters are usually called a mash or a skin in Godot you can think of a measure of skin as an image.
Now skeletal animation is a really great technique to have especially when you're dealing with 2D games because we can take separate images for example and through rigging basically putting images on top of bones.
We can in fact create what looks like to us a complete image over we can control the Newt animation details giving us more animation options then for example taking in a spreadsheet if you're interested in skeletal animation or you want to learn more I recommend three. The first would be. Spine animation which comes from the company esoteric software. They have a plug in for Godot. However it doesn't come with all the features. The next choice could be dragon bones. They also have a plug in.
I'm not sure if they keep up with that.
However I do recommend to look into a third option called creature skeletal animation software and they actually officially support could do at least 3.0 and I emailed them and they said that they are looking to in fact support 4.0 overtake that with a little grain of salt.
Moving on, one thing to note is that this video was recorded on June 20 20 and so the information about skeletal software may be out of date.
If you are watching from the future so let's look at the hierarchy model we were looking at.
So in our skeletal animation hierarchy you usually have a root and there can only be one root in your skeletal animation software and beneath it you'll have bones and sub bones but when you're doing your animation you may have something like this. You have a head you have a right shoulder and underneath that right shoulder you have an upper arm and beneath upper arm you have a lower arm and beneath lower arm you have a hand. Now the rule with skeletal animation is that when you move something higher in the hierarchy it affects everything beneath it.
So for example if you rotate the right shoulder in real life you would expect the upper arm to move the lower arm to move and the head to move and so that's how skeletal animation software tend to work by moving something higher in the hierarchy chain.
You move everything beneath it and as you can see here if we move right shoulder we do not affect the head. And if we move our head we do not affect the right shoulder.
However moving the right shoulder affects everything beneath it and moving our hand does not affect anything above it.
And as you can see here you can sort of see the similarities between how we structure our skeletal animation images and bones to how we structure our scene tree in Godot.
And one thing to keep in mind is that if you move rotate or scale the root bone and then Godot the root node you affect everything else.
So let's go ahead and take a look at that.
So again we have our pick a shoe or pick choose position that x axis two hundred Y axis.
One hundred and our root node is positioned at 0 0 in the game world.
Now let's go ahead and move the root position and see how it affects our pikachu. Now we moved our position to the same position that our picture was in which was two hundred one hundred. And. Notice her peak she was now at the bottom right corner of our screen.
But at the top here we can see that Pikachu still holds the positional value of two hundred on the x axis and one hundred on the y axis.
Now why exactly is that and it's quite simple. Even though our route no in the game world or rather the game universe is at two hundred one hundred watt peak.
Chu sees is different Pikachu sees that in peak Chu's world the universe starts at zero 0.
So when we move our root node or pick a choose X and Y values do not change over they just move along. In relation to where our root node is or Pikachu sees is zero and zero and moves its positional value accordingly to whatever the parent node is. And in this case the parent know it would be
The root node.
Now there are three basic rules with the root bone and in this case the root node and Godot and that is one never change the root node or root bone so never change its position never change its rotation and never ever ever ever change the scale. Now you can go a little soft with changing the position in Godot because it is half game engine. For example if we would like our root node at the middle one reason to do that is because when our Pikachu moves towards the. Bottom right by flipping pick or choose value for example by changing the y value to a negative we can instantly teleport Pikachu to the top right corner and the same thing for bottom left and you would in fact change the root node if you want something specific for your game.
However outside of game engines the general rule is for your root node slash bone don't change the position don't change the rotation do not change the scale. Now if you must have the root no change position rotation and scale. The. Recommended way is to 1 have a root node but keep it again at 0 0 because we never change it. However what you do is you create a fake root node that's a sub node of the root node and from the fake root node you put
Everything underneath it and so everything underneath it thinks that this is the root node however we know better and we know that it's a fake node or in this case a fake root node and from the fake root node we can change its position rotation and scale without affecting the real root node. Well that's all I have for you in this episode. Thank you so much for joining me. Thank you for clicking the Like button and thank you so much for clicking the Subscribe button. If you have any questions or comments please feel free to leave them in the comments section down below. I
I look forward to seeing you in the next episode. Have an amazing day.