The Highs and Lows of Game Engines


This week I was working on changing some of the mechanics for how turning the character works in the game. We started with having the character look in the direction they are moving, but the eventual goal is now to have the character look in the direction of the mouse. The reason for this is to eventually turn the mouse into a target that will allow us to shoot arrows toward it (and enemies in its path).

In trying to implement this, I am reminded of the joys of working within an engine. Getting mouse detection to work properly in PyGame was a chore more often than not. You would have to manually code in a bunch of properties. But inside Godot? It’s already built in! I can just tell it to return the mouse position and viola, I now had the mouse position!

But this introduces other frustrations. If I didn’t really like how the mouse position was being recorded, there is no obvious way (as a beginner at least) of changing how it is being reported. For example, I originally wanted to have the mouse position relative to the center of the screen. So the very center was (0, 0) and anything to the left was negative on the X, and so on. The problem? There was no clear way to do that. I ended up changing some of the animation detection to be on a pixel scale, but this introduced an additional problem. My character movement is based on a -1 -> 1 vector (where moving left was (-1, 0) and moving right way (1, 0)), but the character’s animation was based on a pixel scale. And then in order to get the character to know if they were moving backwards, I would have to somehow marry these two coordinate systems.

This is the difficulty that makes a game engine a double-edged sword. It does a lot of stuff for you, but because you don’t know how it is doing it you can’t easily adjust it. For example, I am using this feature called an AnimationState that uses the position of the mouse to determine which animation it should be displaying. I would like to know which animation it is choosing to play. However, I can’t seem to find a method to return that information. I doubt I can even access the base files where these methods would exist.

As I’m typing this I realize there is probably a workaround to some of these problems. For example, if I want the center to be position (0, 0), I should be able to subtract half the width and half the length from the pixel vector. Tomorrow I’ll go in and update the system and see if any other solutions present themselves…

In the meantime, here is the mouse turning in action:

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *