New assets and a lesson in Rigidbodies

Though I named the game "Jetpack", I always had an alternate idea where the player instead controls a drone of some kind. While looking around the asset store for some nice assets to use, I came across this drone made by the user GameAnime, and immediately felt I should switch to using it instead. I now envision the game being about a remotely controlled drone breaking and entering some high-tech facility (made possible by SickHead Games' Modular Sci-Fi Construction Kit) to complete a mission of some kind.
It was also at this point that I came across a fairly major bug: believing I was pretty much done with the movement mechanics, I decided to make the drone move a bit faster than before - and found out I could phase right through solid walls! It turns out this was due to how I implemented movement in the first place - I wanted to have collision detection so I put a Rigidbody on the player, but not wanting to rely on the physics engine for movement I stored the player's velocity in my player controller and added the velocity to the position of the Rigidbody every frame. I soon realized that by directly setting the position of the Rigidbody I was almost completely bypassing the physics engine, making it nearly useless for collision detection. It did seem to have some effect, however, and it was just enough to keep the player going through walls at the original slower speed, but the faster speed was just too much for it.
To fix this I had to alter the movement functions to instead apply the velocity as a force to the Rigidbody using ForceMode.VelocityChange. Unfortunately this broke my circle strafing controls, as that relies on setting the Rigidbody to a certain position every frame, in order to keep the player's distance from the target constant. Without being able to do this, the player would continuously spiral inwards or outwards while circle strafing, depending on whether I set the player to move in the direction of the next point as dictated by the velocity, or in the direction of that point clamped to a sphere of a known radius around the target using the function I was using to directly set the player's position before. In order to solve this problem I took that first point, used the function to find the second point, and then lerped between the two using a value of 0.68 towards the second point. The result is not perfect, moving very slowly away from the target as the player moves, but it will have to do for now.
Get Drone Wars
Drone Wars
Capstone project for CircuitStream Gamedev course
Status | In development |
Author | GregKitching |
Genre | Action |
More posts
- Fighting the Boss2 days ago
- Meet your enemies2 days ago
- Level development2 days ago
- Adventures in Aimimg2 days ago
- Movement mechanics2 days ago
Leave a comment
Log in with itch.io to leave a comment.