Another important part of the game will be the cube, or actually cubes. But since they all have the same core functionality I will stay with the singular for now. 😀
Since our ghost is… well… a ghost, it can’t interact with physical objects. It is only able to control that mysterious cube.
It can be dragged around by hovering above it and then hold the left mouse button down.
The first thing to consider here was the way the cube actually works. It has to be movable and it has to have collision so it doesn’t float through walls and stuff. Unity has a component, which is called Rigidbody. This automatically enables collision and physics for objects. But it also makes some problems, cause the way you move it through the world is different, then with the character controller.
So, after reading a lot of forum posts and websites, I decided to move it by altering it’s velocity towards the mouse position. (Sounds fancy, eh? ;D) It’s still not
100% accurate, but it shouldn’t be noticeable too much… if at all. Also this is one of those things that can wait until the end of the production to be fixed…
I tried some other ways to alter the cubes position, but they all looked jittery and not like I wanted. The cube should be floating around, so it really looks as if it’s controlled by the ghost.
The ghosts rotation now also follows the cube instead of the cursor, when dragging one around.While this seems to be enough for the cube, it really isn’t. To
properly function there also were a few things that have to be changed.
- The controls of the ghost have to be disabled.
- The ghost still has to be able to move though. So while dragging a cube with the left mouse button, the walk key switches to the right button. (It sounds more complicated as it is though.)
- The ghost has a radius in which it is able to interact with the cube. So if the cube is dragged outside of it, it has to fall down.
- Other small tweaks which affect just code functionality…
And this is the main functionality of all three cubes. Dragging and dropping…
That was much more complex than I ever thought it could be… O.o