Most video games allow you to switch the camera angle. I've added a button here to allow us to do just that. So we've got 12345 different camera angles. So let's have a look at how we do that in code. We know dealing with the v two folder, so have a look at the v two folder, game dot j s to follow along with the description in the init function in the loader for the girl walk SPX, towards the end of that, there's now a method of the game called called create cameras. That's where we create the cameras.
There's also a create dummy environment method which creates the yellow blocks You've just seen. So let's have a look at the Create cameras. Here's the Create cameras method of the game. What it's doing is it's creating a bunch of an object 3d. Object 3d has got a matrix, a position and a rotation. And we're setting the position.
And then we're setting this particular object to have the parent of our Character. The Character has been stored in the property of the game called this top player object. So we've got a front, we've got a back, we've got a wide, we've got an overhead, and we've got to collect. That's a close up of the character. Once she's crouching down, we store them In a objects from back wide overhead and collect, we then set our active camera to be the wide one. Set the camera fade value to be point one.
And then we do a set timeout, which changes the active camera to the back one. After two seconds, the active camera is actually a setter. And we take the object and apply that to cameras dot active. We've made a small change to the animate method of the game. We check whether or not cameras active is defined. And if it is, we're going to use a method of the vector three class that's part of the three library to blend between two different vectors.
This is going to move towards this position, this amount. So since this is set to point one, as we saw earlier, it's going to be, it's going to move towards that position by 10%. Get world position finds the world position of an object. And it's a particular point on the object. In this instance, we want we want the root of it, which a three dot back to three, without any parameters will give a zero vector, so it'll be 000. So in other words, what's the world position of 000 in this object, and then we find the position of our character.
We clone it and then we move up the y value by 60 units. And then we get our camera to look at that position. So what's happened there is it's moved its actual position of the camera to be moving from where it currently is to towards where the active camera is positioned. And then it looks at the player every time so he does that every time. Anything up to 60 times a second. And that's gonna allow the camera to boot to blend between different positions.
And how do we choose those positions? Well, if we go to the to the game, first of all, we'll open the console. Then we need to delete game player, cameras, active otherwise that's going to override when to store the game player object position we need to stick to that position and then we can set the camera position to say that and then we need to look at position it too far either So, come back down to 500 There we go, sadly, but it allows you to get the angle of a camera and then you clock these numbers and use that as your value. And for your, your camera that's attached attached to the player. And using that method, I selected the values to give those results