JPtheK9
  • Member for 7 years
  • Last seen more than a month ago
  • New Mexico
How do we make online games deterministic?
Accepted answer
8 votes

It's actually the other way around. Games are made deterministic to be online. The basic idea is to send commands rather than game state. If you have a function F(X) = Y and you need everyone's Y to ...

View answer
Creating a countdown Timer in Unity
Accepted answer
6 votes

Alternatively, you could use System.Timers.Timer which is probably the most performant of any solution. The following example shows a countdown for 100 seconds. System.Timers.Timer LeTimer; int ...

View answer
Packet size vs packet frequency
Accepted answer
5 votes

According to the answers on this page, about 512 is a safe amount for ipv4 because nearly all consumer's hardware will be able to support that size. For ipv6, 1500B is the maximum safe packet size. ...

View answer
How do I make an endless road in Unity?
3 votes

Many infinite runners scroll the road rather than move the player forwards on the road to make the road truly infinite. You can do this with 2 alternating game objects. public GameObject[] RoadPieces ...

View answer
Circle Depth Penetration
3 votes

Yes, you can do this with no expensive trig at all. Steps: Find the distance between the 2 circles. Find the combined radius between the 2 circles. Subtract the distance from the combined radius to ...

View answer
2D Collision response - rotating, moving polygon hitting a wall
3 votes

You've got the moving part right but the rotating adds a significant amount of complexity to the problem. Luckily, you can hack in rotational velocity with a formula mentioned here. It approximates ...

View answer
What is a reasonable way to avoid GC issues in Unity?
Accepted answer
3 votes

If you're really hardcore and want to take the extra optimization, a static object pooler will be the best choice performance-wise. Most of the time, an instance object pooler will work perfectly. It ...

View answer
How can I get the user altitude from an iPhone using Unity 3D?
Accepted answer
3 votes

LocationInfo is a struct so you need an instance of it to access its members. You can find a populated instance under (LocationService.lastData)[http://docs.unity3d.com/ScriptReference/LocationService-...

View answer
Endless Running Game - Changing Lane Function in JAVA
Accepted answer
3 votes

You should do a bounds check as you mentioned then reduce the velocity so you don't get shaky behavior. You kind of got it but I'm not sure what displacement does. //This code goes after velocity is ...

View answer
How to detect collision of a wall with grid movement?
Accepted answer
3 votes

If you're using a grid, you shouldn't be using Unity's physics for collision detection - use the grid. Get your position on the grid then do something like this: public bool GridCast (Coordinate ...

View answer
Comparing two strings in Unity C#
Accepted answer
2 votes

If you want to be hardcore about it... public static bool StringComparison (string s1, string s2) { if (s1.Length != s2.Length) return false; for (int i = 0; i < s1.Length; i++) { ...

View answer
Transition between normal and slow motion
Accepted answer
2 votes

Here's a function that interpolates between Start and End quadratically by T. float Qerp (float Start, float End, T) { //The quadratic stuff T = 1 - T; T = 1 - (T * T); float ...

View answer
Only send moves for P2P 2 player LAN game?
2 votes

Maps, items, monsters, etc. gives you many factors that can be tipped out of balance by 1 small difference in a floating point operation. A character moves a little bit more to the right, he bumps ...

View answer
Is Physics2D.BoxCast a safe alternative to a row of raycasting?
Accepted answer
2 votes

Box cast would probably be more performant since it's only checking 4 vertices but it'll definitely be more accurate, at least depending on what you want. Good idea! Example use: RaycastHit2D ...

View answer
Unity - How To Save Some Variable WIth PlayerPrefs?
Accepted answer
2 votes

PlayerPrefs are not designed for saving scores. They are easily modifiable by the end user in a text file. Instead, you should serialize settings, replays, etc. that players have no motivation to hack....

View answer
Which is the better way to distribute server workload for MMO server?
Accepted answer
2 votes

Without a doubt, an executable per map would be the best option because servers run collisions detection. Collision detection increases in complexity by O(N) so a single instance with 500 objects will ...

View answer
Simulating beer pong physics in Unity
2 votes

This is fun! The trajectory is just a bunch of mathfz and a line renderer. Check out this post for more information on that which details how to calculate the trajectory. Line renderers are definitely ...

View answer
How to enter a level when touching an object
2 votes

Detect collisions with OnCollisionEnter then load your level there. I.e.: void OnCollisionEnter (Collision col) { Application.LoadLevel("Level1"); } If your character's Collider is a trigger, ...

View answer
Property replication vs RPC notifications
Accepted answer
2 votes

If you're using, for example, Unity's standard networking without an authoritative server, an RPC would be better because syncing something every frame can be VERY expensive because the packet header ...

View answer
Unity Rigidbody gets pushed through collider by another rigidbody?
2 votes

Unity's collision detection is discrete so if an object passes through another object within 1 simulation frame, the collision will not be detected. If the collision is already detected, however, ...

View answer
Synchronisation on a non authoritative networked peer to peer scene
2 votes

The key to large-scale synchronization is determinism. Basically, if you can plug X into a function and get the same Y on all computers, you can send X instead of Y. For example the de facto RTS game ...

View answer
How can I manage the deceleration of units so that they arrive on-target?
Accepted answer
2 votes

I found the answer thanks to this essay Daniel posted. It's something like this (from page 10): closing_distance = max_speed * 2; desired_velocity = normalize (position - target) * max_speed if (...

View answer
Unity3D: Disable player input but not character movement?
Accepted answer
2 votes

You could make a bool that, if true, checks for all input. If false, you essentially turn off all input. bool DoInputs = true; IEnumerator Dash() { if (DoInputs) if (player.GetAxis("...

View answer
How do I generalise Bresenham's line algorithm to floating-point endpoints?
1 votes

I ran into the same problem today and made a pretty big mountain of spaghetti out of a mole hill but ended up with something that works: https://github.com/SnpM/Pan-Line-Algorithm. From the ReadMe: ...

View answer
Animation impulse system?
Accepted answer
1 votes

Reverted to UnityEngine.Animation. Works like a charm and has no performance hits.

View answer
(Unity) Optimised networking solution for many moving objects
Accepted answer
1 votes

For 200+ moving objects, you're definitely going to want to make your game lockstep. With lockstep, comes the need for determinism but that shouldn't be too hard for bacteria (which can be simulated ...

View answer
Efficient container(s) for units in an 2D RTS game
1 votes

Use an influence map for target searching. Have a grid and on each node, reserve a spot in a collection of units for each team. For each unit, generate a collection of coordinates within range and ...

View answer
How do I use playerprefs to make ui slider keep the sound settings?
1 votes

using UnityEngine; using UnityEngine.UI; public class SliderSaver : MonoBehaviour { public Slider slider; void Awake () { slider.Value = PlayerPrefs.GetFloat ("Slider value"); ...

View answer
2D Infinite Runner : how to manage background layers?
1 votes

Many infinite runners scroll the world instead of the player to prevent the problem of float overflow. Also, this makes several things easier to manage like player movement and the camera. For ...

View answer
Efficient Collisions Iteration?
1 votes

The solution was a lot simpler than the other things I was thinking of. I store all CollisionPairs in a separate collection and iterate over that collection. This allows me to do what I was doing ...

View answer