Hot answers tagged

43

I've worked on the networking code for two real time AAA networked games, one for smartphones and one for a handheld console. To directly answer your question "why", well, some games use one or the other because it suits them better than the other. This depends not only on the type of game, but also on what type of network we're talking about (linked arcade ...


29

You interpolate when you know the 'before' and 'after' values. For example: in a point-and-click game, player is currently at position X, and from his interface, he clicks on spot Y. You must interpolate the displacement between X and Y because you know the two values. You extrapolate when you guess what's going to be future value, based on what you ...


20

You want to separate update (logic tick) and draw (render tick) rates. Your updates will produce the position of all objects in the world to be drawn. I will cover two different possibilities here, the one you requested, extrapolation, and also another method, interpolation. 1. Extrapolation is where we will compute the (predicted) position of the object ...


20

Okay, I think you have two problems going on here. The first problem is with mipmapping. In general, you don't want to naively mix atlasing with mipmapping, because unless all your subtextures are exactly 1x1 pixel sized, you will experience texture bleeding. Adding padding will simply move the problem to a lower mip level. As a rule of thumb, for 2D, ...


16

Here's a quick outline, off the top of my head, of an algorithm that ought to work reasonably well. First, calculate the direction the object is moving, and check whether it's closer to horizontal or vertical. If the direction is closer to vertical (horizontal), adjust the position of the object along the direction vector to the center of the nearest pixel ...


15

One option that'll be a lot easier than fiddling with mipmaps and adding texture coordinate fuzz factors is to use a texture array. Texture arrays are similar to 3d textures, but with no mipmapping in the 3rd dimension, so they're ideal for texture atlases where the "subtextures" are all the same size. http://www.opengl.org/wiki/Array_Texture


14

Blue vector can be calculated easily: red - black (the sign between vectors is minus). But if you want just to interpolate between black and red vector, you don't have to calculate it. Linear interpolation is just linear combination. So you can just take: alpha * black + (1 - alpha) * red, where alpha has to be from interval <0,1>. If alpha will be 1, ...


14

You can use random seed. Select same 32-bit value in server and client (or server can send it to client at start). Use it as seed for random generator. You can send actual seed from server to client with game state update. If you don't want to send it you must be sure that client and server generates same number of random numbers by this random generator. ...


14

Interpolation is done when you have both a start and end value, and you want to estimate what happens between this start and end value. An example would be to move a player from Position A to Position B in a fluid motion. Extrapolation, is done when you have a start value, but do not yet have data for the end. You can then extrapolate based on what data ...


12

I'll assume your t goes from 0 to 1. (If not, just multiply to scale it appropriately.) Figure out what proportion (0–1) each side is of the perimeter. (side length / total perimeter) To find how much of every side is “filled in” at time t, iterate through sides, subtracting their proportions until t is depleted to a negative value. That last edge (which ...


8

You have jitter, because you lag is changing constantly. This means, that while server sends updates exactly every timeBetweenTicks ticks, the client receives them after some variable time. That time is probably close to timeBetweenTicks on a good connection, but not exactly equal (And besides, you may have server lag and different clock speeds on server and ...


8

I have solved this problem before with some success with an approach I call "network shadows". I don't know if this is something other people do, but it's always worked for me. Each entity which is being synchronised across the network has an invisible network shadow entity. When an update comes in from the network, you teleport the shadow directly to the ...


8

For this reason, you'll find simulations are often run 1 or more frames ahead of what is in fact being rendered at given point in time on a give client. So in other words, what you render might in fact be the second last frame, not the last frame. Search this article for all instances of the word "ahead" and I think you will start to get the picture better ...


8

You are looking for a grid traversal algorithm. This paper gives a good implementation; Here's the basic implementation in 2D found on the paper: loop { if(tMaxX < tMaxY) { tMaxX= tMaxX + tDeltaX; X= X + stepX; } else { tMaxY= tMaxY + tDeltaY; Y= Y + stepY; } NextVoxel(X,Y); } There's also a 3D ...


8

Yes it's possible, but it's not without its complications. While frame interpolation can work real-time on videos, that isn't necessarily the case with video games. Even though this is processing real-time on videos, the software is able to "look ahead" to the next frame. This is a pretty critical component of interpolation. This is where the issue comes ...


7

From what I see, the game loops you are trying to use are somewhat specialized. I don't know why you chose those ones, but in my opinion you are trying to solve problems that don't exist in the first place. Instead of copy-pasting a game loop from some site, I suggest you think about how your game is made and what your priorities are, and then create a game ...


6

Put very simply, linear interpolation of matrices is not always a good idea. If you have an animation you are trying to accomplish, and you are using matrices to handle the bones rotation, you can't just take a linear combination of them. You'll need to use slerp, extract the axis of rotation and interpolate the angle and recalculate the rotation matrix, or ...


5

In general, lerp functions don't take a speed, they take a parametric representation of how much they should be in between your start (A) and end (B) parameters. Of course, if you have a constant speed, you can figure out how long it should take you to go from A to B doing some simple math. If you're moving at X m/s, and you need to travel Y m, then you ...


5

While the server has the final say on the position, it should do that by verifying and sanity-checking what the client sends over as the inputs and position. I say this because what you're doing is moving the player immediately and the expectation that creates in your code is that the client is the real position. You think it generally works well, but it's ...


5

Two that you're missing which immediately stand out to me are GJK and MPR. GJK is an algorithm for finding the closest point of two convex polygons. With a little bit of extra work you can use it to find incident points for intersecting objects, and hence calculate a collision manifold. This is done via polygon clipping, same as if using SAT, but GJK ...


5

Let's assume you want a circular arc from point A to point B, guided by control handle H which is the intersection of the tangents at A & B (and thus equidistant from A & B). Circles being the bread & butter of geometry, there are a hundred ways to skin this cat - but here's one... If we define: midpoint = (A + B)/2; perpendicular = (-(B - ...


5

A system along these lines has been used in The Force Unleashed. I'm not aware of other titles that have used it though.


5

After playing with this function more. I realise that the bezier control points are acting similar to magnets. If I spread the control points so that they are positioned along a straight line with equal distance between, then the animation works as expected { p0: new Vector(0,0), //Start point p1: new Vector(.333,.333), //Control point 1 p2: ...


5

I usually solve this using Catmull-Rom splines. Instead of using control points, you simply specify the two points between which you'd like to interpolate, as well as a "previous" point and a "next" point. If the 4 points all lie on the same line and are evenly spaced, the interpolation will be linear. In the image above, there are four points p0, p1, p2 ...


4

Taking this picture: AB is the red vector from A to B. Say P is 25% of the way from A to B. The basic way to get to P from the origin is A + ( B - A ) / 4 = 3/4 A + B / 4 So 3/4 A and 1/4 B. Another way to find that is saying you want a vector 75% "close" to A, and 25% "close" to B. (A vector that is 100% "close" to A is just the A vector.) So ...


4

Do not attempt to replicate the whole game state. Interpolating it would be a nightmare. Just isolate the parts which are variable and needed by rendering (let us call this a "Visual State"). For each object class create an accompanying class which will be able to hold the object Visual State. This object will be produced by the simulation, and consumed by ...


4

Looking at your second log file, I'm wondering if you're calling resetSmoothStates() in the right place? On lines 42, 46, 50, and 54 you can see that the original position stays at a constant [661.2183], indicating there hasn't been a physics update. On line 43, it looks like you're smoothing between the previous original position, [671.2361], and the new ...


4

I took a quick look at your example and your code. You're extremely close to solving this, so I don't mind helping with a question that looks suspiciously like homework ;). In data.js, you are assigning the same UV coordinates to the front and rear faces of the cube. The coordinates seem to be ([0,0], [0,0.5], [0.5,0.5], [0.5,0]). This means that you can ...


4

Looks like the issue could be caused by MSAA. See this answer and the linked article: "when you turn on MSAA, it then becomes possible for the shader to get executed for samples that are inside the pixel area, but outside of the triangle area" The solution is to use centroid sampling. If you are calculating the wrapping of the texture coordinates ...


4

A more generic approach is detailed on Wikipedia. Essentially, that article explains there's no non-iterative method to find the generalized combination of N quaternions with weigths w_i. Nevertheless, if you can supply an approximation of that quaternion "mean", you can iteratively refine it using these update equations: So you could start with m_0 as ...



Only top voted, non community-wiki answers of a minimum length are eligible