CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Follow publication

Implementing a basic mouse follow logic in Godot/C#

Let’s setup a simple 2D movement scheme for our little ship!

Mina Pêcheux
CodeX
Published in
11 min readFeb 8, 2023

With the ever-growing diversity of gamepads, and mobile screens, and VR controllers, it looks like player inputs aren’t as easy as they used to be. Long gone are the days where you had a simple joystick to change the course of your paddle in Pong!

And yet: there are some gameplays and input types that seem to survive throughout the years, such as the well-known “your avatar follows your mouse”. This interaction scheme is quite common in small mini-games, and it is actually not that hard to implement…

So, today, let’s discuss how we can implement this mouse follow logic to have a little ship avatar follow the cursor in a simple 2D game, using Godot and C#!

This tutorial is available in video or text format — see below for the text version :)

Check out the Github repo with all my Godot tutorials! 🚀

Quick demo

By the end of the video, we’ll have this basic scene with our ship avatar in the middle, that follows the position of our cursor on screen:

We’ll give our avatar a particular speed, so that it doesn’t just instantly jump to the mouse position but rather glides towards it, which will allow us to avoid the asteroids around us while keeping it the game fairly challenging. We’ll also do some 2D drawing to visualise the target position more clearly.

As usual, don’t forget that if you want to get the files of this tutorial directly, you can…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Mina Pêcheux
Mina Pêcheux

Written by Mina Pêcheux

I’m a freelance full-stack web & game developer. I’m passionate about topics like CGI, music, data science and more! Find me at: https://minapecheux.com :)

No responses yet

Write a response