Welcome back! I have more Space Farm updates. To help you navigate these posts, I've added a "space farm" tag that should bring up anything related to this project. I'll try to add other useful tags as I go, especially whenever I include code snippets.
As I might have mentioned in the last post, this time around I worked on letting the player interact with the game world. Since I don't really have a clear plan for the gameplay just yet, I figured a cursor might be a good start. I created something similar in a tower defense prototype in GM, so I had already worked out some of the logic at some point in the past and felt it should be possible to make again. Seems reasonable enough, right?
So I started with simply spawning an object called "cursor" on the map. Like everything else in this game so far, it's a cube. I put a translucent green material on it so it'd stand out a little better. Life was good.
And then I tried to make it follow the mouse. This was... not as easy. As I'm sure I'll state a million times in this devlog, I'm not super familiar with cameras, especially in a 3D space. So translating from screen coordinates to world location wasn't intuitive for me. I've written the kinda code where it works but I'm not really sure how-- Unity's "screen to world point" function got me most of the way, but I needed to add some funky-looking math to adjust the received value to account for the camera angle. Without this adjustment, the cursor would float off the ground near the top of the screen, but sink through the floor near the bottom of the screen.
After correcting this, I decided to go ahead and lock the cursor's movement to a grid, as well. I figured one of the first player actions I'll add is placing things in the world, and as a player I always appreciate a placement grid so I can plop things down all willy-nilly and have it still look decent. This should also theoretically make things easier to program later, as I won't have to deal with detecting multiple objects under the cursor when the player clicks. The design document for this project is still pretty bare-bones, so I might change this later.
Even with all the Googling, I'm having fun. I think next I'll start on the farming tools. It's kinda hard to have a farming game without the part where you grow plants, after all!
No comments:
Post a Comment