The Game

Published April 22, 2024
Advertisement

This is part two of this project! For part 1, see here

This week I will be taking my previous dive into Godot and multiplayer and bringing it up to a higher level! I think what I would like to do is to make some sort of platform racer. However, I would also like to see if I could set up the net code to go beyond purely localhost, and even make a build that could be sent to my friends and still be able to play together.

I started with attempting to see if I could make some friend capable of connecting to the game from different wifi networks (so no longer local OR LAN). I am going to keep this part fairly vague just for wifi security reasons, but in general, google is my friend when it comes to learning how to port forward and set my laptop up to accept connections. I set my ip in the peer.create_client function and started testing. This involved me sending builds to my friends and seeing if they could connect (it worked locally with the changed ip). I followed this short guide to learn how to build: https://www.youtube.com/watch?v=cXahUh9Zfho

However, I could still not get it to work beyond purely local connection. Changing the IP to connect to worked on my laptop, even when in a build and not in editor, but the moment I changed it to a different PC or wifi network it stopped working. The code was clearly working, so I will assume that, unfortunately, I failed when setting something up in the network settings. I am currently renting, and some internet settings can be beyond my control even if it seems like I can change them (speaking from experience with failed minecraft servers…).

Regardless, the local connection still worked, so I wanted to make some sort of game out of it. I adjusted the default speed and jump velocity settings and decided to set out on making a racing platformer. I wanted to figure out Godot UI, though, as it had bugged me last week when the buttons were objects in the scene and not attached to the camera. I was able to fix this with this forum post:

https://forum.godotengine.org/t/how-to-make-the-ui-follow-the-camera-and-not-the-player/5040/2

The buttons are now attached to the camera! This allows me to display any sort of information I want to the player, such as a timer. However, first I needed a way to trigger the timer, and to make it a fair race, I figured I would make it trigger off of a start line. I learned that the best object to use for this would be an Area2D and using this documentation I was able to set up a basic one! https://docs.godotengine.org/en/stable/tutorials/physics/using_area_2d.html

So, now I have an easy way of triggering a timer, and a replicable way to stop the timer as well. To make the timer, I followed this youtube short: https://www.youtube.com/shorts/M-0UNa8M5bE

Then, I connected the timer to the area by adding a bool that would flip to true when the area is entered by the player:

Then just to make sure the idea would all work, I made the finish line and also made it so the start line would reset the time, so you could do multiple runs within the same instance.

The last thing I wanted to do for this project before making a quick map to play on was to make obstacles to avoid otherwise your time would be increased. I once again made a new 2d area, added some polygons and made another 2 triggers (one to add the time, one to delete the object as it has been collected) and:

It works perfectly! Lastly, all I need to do is make a map and put out more obstacles and this project is done!

The map is short but gives a good idea of what is going on here. I am bummed I could not get the multiplayer to work beyond local, but I think that mostly has to do with trying to interface with a laptop instead of some sort of dedicated server.

Previous Entry The setup
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

The Game

9852 views

The setup

9565 views

Groundwork

12285 views
Advertisement