location communication
One of the important systems for this game is player location on death. In my previous post message received, I talked about how I got this working with the new networking system in Unity.
What was missing from this was the actual player coordinates; I was just sending a hard coded string. I had a bit of time to mess around with it and decided I’d get some real data being sent. Turns out it was pretty easy!
Instead of setting msg.deathCoords = “0,0”, I needed to have it send the transform position coordinates of the player, specifically, just the x and y values, and I needed them as a string. Well, ToString() worked nicely, but I also didn’t need a float value to eight decimal places or whatever, so I’m not sure if it’s the “best” way, but typecasting the transform position as an int did the trick here.
So in the screenshot above, you can see I’m recording the server timestamp, and publishing a static “player died at coords” message. In order to have the actual coordinates published at the end of that, all I needed to do was change:
msg.deathCoords = “0,0”
to
msg.deathCoords = ((int)transform.position.x).ToString() + ", " + ((int)transform.position.y).ToString();
Simple, no?
It didn’t take much work, didn’t cause me any problems, and was quite easy to implement. But I’m fairly pleased with the outcome because I’ve achieved a specific goal I set for a session of dev work, and it’s one less thing I have to worry about later. Unless I break it.
Hours So Far: 86













