Mario Kart Dev Diary: Orbit Camera

Mario Kart Dev Diary: Orbit Camera

Mar 3, 2019. | By: Lewis Bond
1 min

Orbit Camera

When a person finishes a race in Mario kart it lerps round to be in front of the player. The link below shows the effect. I have been working on an orbit camera to do this effect. MARIO KART EFFECT

Since it need to circle around the player I knew I needed to use trigonometry. As Maths Is Fun shows, I need to use the opposite and the adjacent to get the hypotenuse. Once I had this it was easy. The center of the model was used as the pivot and the angle was changed to make it spin around the kart. M_dpos was a vector3 used to put the camera a set distance behind the car and to get the x of this vector was used as the opposite, the z was used to get the adjacent.

angle += amount;
sin(angle / radian) * vector3.x;
cos(angle / radian) * vector3.z;

The angle is increased by an amount every frame and the angle is then divided by a radian. The sin and cos of that result is then multiplied by the respective vector axis to get the position. Just by increasing the angle the position of the camera changes as shown in the image below.

The orbit camera in action

Problem

This issues with this method is that it uses two dimensional maths, but I need it to work in three dimensions so what way the cart is facing it will orbit at the amount I want. For this I will have to incorporate the matrix and orientation of the car so it orbits around no matter how the car is rotated.

PREVIOUS BLOG POST NEXT BLOG POST

About

Those who can do and those who can't teach games design.

Our Bunker



United Kingdom.