As I continue to develop Gym Empire I find more and more just how different working in 3D is. Creating objects in the world is not too difficult and placing them just involves understanding that there is a 3rd axis that you need to accommodate for when defining the position. It however starts to become trickier when you need to start dealing with rotation. Rather than directly defining the Quaternion (don’t ask me but it’s a method for defining angles) you need to provide changes in Euler angles. It all makes for a more complex system when defining where in the world your object needs to be and which way it is facing. I all honesty though, it’s not really that difficult. It just requires a bit more understanding and a few extra lines of code.
The part I’m currently struggling with is moving an object in a 3D environment using the mouse. Essentially drag and drop in 3D. To do this you need to use something called raycasting. In the simplest of terms the concept is to cast a ray from a specific point on the screen (in this case the mouse pointer location) to a point in the game world and translate the originating point to a relative world point. I’m currently struggling with this as there seems to be a lot of drift as I reach the edges of the screen. I assumed (and would like) that it worked in a way whereby the object would appear stuck to the mouse, but it seems like it translating the mouse movement from its originating point of the first click into a distance that the object is moved i.e. that the if the object moves a 25% up the screen, the object moves 25% across the game world. This means that I have to keep picking up and dragging the object until it finally gets to the desired point. I am pretty certain that this is not the normal behaviour of raycasting so I am assuming I’m missing something in the code. My current theories are that either I am somehow measuring the mouse’s movement rather than location or that by only moving in 2 dimensions (i.e. it slides across the gym floor rather than floating up as well) the raycasting doesn’t work how I expect it to.
Last week had a nice eureka moment for Project ZATO which opened the gates for a nice flurry of game mechanics being added and really taking the prototype forward, I’m hoping for the same this week with Gym Empire!
