Sunday, February 23, 2014

Long collisions

Made the system compatible with long single movements. This was done by sweeping a collision sphere along the entire length of the targeted movement, to check if we are supposed to be able to go the entire length. This is one movement:


Passing through

I fixed a bug today where the colliders would sometimes pass slightly into one another.
Variations in framerate would make the raycasts not able to keep up.
I fixed this by checking how far we wanted to go, and if the wall was close enough that we only could move part of the way we scale the vector meant to stop the movement to remove only the excess that would cause us to move into the wall. Earlier the script only stopped you if you were actually touching the wall. The collisions are much closer to perfect now, and framerate independent.

Collisions

So I am going to make a game for my bachelor's degree project.
We are 3 people, all programmers, who will be making a game together in Unity.
The game will be a 3d/2d top down dungeon type game with networked multiplayer (my bachelor's degree is in Networking)

Today I started a bit prematurely, so I can get the basics working. The plan is to avoid any wasted work, like: "Oh you did that, well the collisions need to work like this so you have to rewrite everything".

And that brings me to my first topic: Collisions.
We decided not to use the built-in physics in Unity to reduce complexity. This also gives us the ability to ignore object syncing, one of the more shaky features of the built-in networking of Unity, Raknet. We may still use local client-only non-interactive physics for things like explosions.

I now have working 2d collisions, and objects will stop at the correct spots reliably. This movement is seated in the "Update()" function of Monobehaviour, which runs once every frame.

I have generalized the collision checker into a script called "CharacterMover", anything that needs collision checking can attach the script to its main transform, and then move using the Move() function.

Here is an example of a cube attempting to pass through a wall. The green lines are the general directions it is attempting to move in, through the wall and to the left. The blue lines are the counteracting vectors, removing only the components that are attempting to move the cube through the wall. This works at all angles. Here is a normal wall:


And a simple corner: