Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

Initial Player Controls

Overview

Wow... getting the initial player controls for this game was way more difficult than I was anticipating. I felt like I was banging my head against a wall for about two days just trying to get the placeholder spaceship to look at the mouse. I think I watched about five youtube videos on how to do this with the new Unity Input system, but alas there was no luck.

The only way I was able to get it to work was by looking at a game I had never completed about a year and a half ago on my old computer and lift the code to work for my specific player controller of this game. The below code is what I ultimately used to get the controller working.

void Update() { 
      Vector2 moveInput = playerInput.player.movement.ReadValue<Vector2>();
      rb.velocity = moveInput * speed;
      mouseScreenPosition = playerInput.player.mouseposition.ReadValue<Vector2>();
      mouseWorldPosition = main.ScreenToWorldPoint(mouseScreenPosition + Vector3.forward * (main.transform.position.z * -1));
      Vector2 targetDirection = mouseWorldPosition - transform.position;
      transform.up = targetDirection * -1f;
}

I hope this helps anybody else trying to figure this out on their own. I feel like this is a pretty straight forward task that most games implement, which made me feel more defeated than ever when it was taking me so long to figure out. Haha but in the end I was able to get it to work (see the above gif) and wow have I never been so ecstatic! I quite literally jumped for joy when the space ship started following my mouse!

If this taught me anything, it is that I should really learn to step away from my computer and take a break when I hit a wall. I can be so stubborn sometimes, and this leads me to keep trying and trying and trying. However, this fix was a simple case of me stopping early last night and then not coming back to my computer until after work today. Coming in with fresh eyes really helped me see what I was missing and fix the code appropriately. 

Next Steps

I would like to start adding the following features to this jam game next:

  • Parallax for the space background
  • Create more worlds in this "open" galaxy
  • Create more vector art for the game
  • Find some cool galaxy tunes
  • Create the actual shooting of the seeds mechanic
  • Created the AI enemy bugs
  • Implement the planet recovery mechanic

Now that I have gotten over this hurdle, I feel much more confident in continuing on with this game! I feel like there is always a hurdle like this when I am starting on a new game. Then once I get over it, it is just all I can think about regarding what more I can add to my game. I hope you all stay tuned to see more updates from me on this new game jam game!