Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Unity3D + Amazon GameLift: Focus on The Realtime Script

Alexandre BruffaFollowBetter Programming--ListenShareIn a previous article, I showed how to build an entire real-time multiplayer game with Amazon GameLift and Unity3D. The process implicates creating game sessions and player sessions with Lambda, guest access to the services with Cognito, and a game server with GameLift.We could also find out that the game server’s behavior is defined by a Script written in Javascript: the Realtime Script. This article will detail how this script works and how to create game server events.Note: You can also check out the video version of this blog postThe Realtime Script is a collection of callback functions the game server calls during its lifetime. In other words, we can implement custom behavior for each of these functions. All the callback functions are described in the GameLift documentation; here are the main ones:Furthermore, the game session provides interesting functions such as:All the game session functions are available in the GameLift documentation.In my previous article, I provided a very basic script making the game server act as a simple “dispatcher”. The game server notifies the players if someone joins or disconnects and resends a message sent by a player to the other players (i.e., action, life update, etc. ).This time, we will create a non-related player event: a meteorite will fall on the map from time to time. No matter how many players are on the map or what they are doing, this event is 100% managed by the game server.Our script contains a loop function used to check if the game session should be ended. We will integrate our new server event in the loop function:We modify the script, adding the new feature in the loop function:Notes:You can find the entire code in the resources section of this article ⬇️In the Unity client, we implement the new event sent by the game server with a countdown and cool VFXs:It looks awesome! For the meteorite and the explosion, I used assets from the Voxel Arsenal assets. I managed the explosion force field with a Sphere Collider in trigger mode:I used the OnTriggerEnter and the CompareTag functions to detect this force on the player. Then, I normalized the differential vector and applied a ratio to it. I found that a ratio of 200 creates a cool visual effect. Finally, I applied the AddForce function to the player’s Rigidbody:At first glance, the Realtime Script can be complex and challenging to understand, but once you master it, you have total control over the game server’s behavior and can do absolutely what you want! Meteorites, snow, rain, sunshine, real-time updating environment, non-player characters, etc. The only limit is your imagination!In the resources section, I provide a Unity package of the game I showed in the demo. The meteorite and explosion assets are not included because of the license type.You are free to use all the resources I provided in this article. Please ping me if you use them to build your game; I would be delighted to see the result!Here are all the resources mentioned in the article:For the demo, I’m using the Voxel Arsenal assets.----Better ProgrammingI write cool stuff about Unity3D and AWS ★ AWS Community Builder ★ AWS certified ★ https://alexandrebruffa.com ★ Support me at https://ko-fi.com/alexandrebruffaAlexandre BruffainBetter Programming--1Dmitry KruglovinBetter Programming--46Sergei SavvovinBetter Programming--12Alexandre BruffainBetter Programming--2Alexandre BruffainBetter Programming--1Samantha Gittemeier--Rabin Lamichhane--MAFinMAF Blog--Yan Kalbaska--1Alika 7up--HelpStatusWritersBlogCareersPrivacyTermsAboutText to speechTeams



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Unity3D + Amazon GameLift: Focus on The Realtime Script

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×