Movement and rotation

The game that my group picked to work on is Burn, Witch, Burn! In this specific game you are riding on a floating broomstick and as such the movement of the player character is supposed to feel floaty and have some kind of air friction and acceleration. I also wanted the direction the character is facing correspond to the direction of the velocity vector.

At first we tried to code the movement completely without using the built-in physics of rigidbodies in unity. It ended up in about 20 lines of code and wasn’t really working that well. After some researching (forums and the unity API site) and testing I found out about the AddForce which does exactly what you think it would. Parameters such as mass and drag of rigidbody can be changed in such a way that character slowly loses speed after the button for movement is released. The diagonal movement we got from the AddForce was too fast as it got 2 different vectors at a 90 degree angle got the force of the hypotenuse between them. This was solved by normalizing the vectors which makes it have a maximum magnitude of 1.

The next piece of the movement was the rotation. In the first iteration we made the character would rotate depending only on the input of the keyboard. So pressing left would turn the player left even though it still was moving another direction. By using some math functions that calculate the radians of the x and y velocity and converting them to degrees we could make the facing of the player correspond to the velocity vector.

The last problem was that the rotation was to fast. I tried many things through code but didn’t manage to find a good answer. At last I found out that there is a way to change the physics options in unity. One of the options controls the maximum rotation speed, so I lowered it until the rotation felt better. I’m pretty sure that there is still a lot of improvements to be made in the movement as I learn more about unity and how to code in it.

movement

One thought on “Movement and rotation

  1. Hello!
    I believe you did a great job in explaining exactly what kind of movement you wished to have in your game and what sort of approached you had to the issue. Despite the fact that the terms used, such as rigidbody, and the overall explanation of how your movement worked was a tad bit advanced would it of been someone else that isn’t a programmer like myself, I believe it is probably enough as the topic of movement and physics tends to become advanced, after all.

    I believe you could have made it easier on other readers however, would you have put in more detailed explanations on things like exactly what a rigidbody is and how it functions, even though you explained that it contains the parameters mass and drag, you also hinted on that there’s more to it than just those two, which could have been used to explain it even further.

    You can also ask yourself “Why?” more often when writing this, one such example is the rotation part where you explain the speed of it was too fast, why? Was it because it was simply too difficult to control it or was it a matter of balance because it would be too easy for the player?

    Other than that it was a good read and I hope you will learn to improve the game even further as you learn more about programming and Unity!

    Like

Leave a comment