|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Defeating Lag With Cubic Splines |
|
![]() charliekoo Member since: 9/27/2006 From: Center cambridge, NY, United States |
||||
|
|
||||
| do anyone explain to this article? expecialy. i don't understand for second and third coordination is operatied |
||||
|
||||
![]() db82 Member since: 6/6/2007 From: London, United Kingdom |
||||
|
|
||||
| Hi I'm trying to get this formula working in a top down tank game in flash. The idea is to predict the next position of an opponent tank and move the opponent tank towards that position using a cubic spline. The opponent tank receives a new positionObject every 200ms. The positionObject contains the new x, y, _rotation and current speed variables. The current speed is a vector (??? I think this is the right term. The xSpeed && ySpeed is caclulated from the same 'speed' variable ???). The newXAcc and newYAcc acceleration values are calculated based on the change in speed since the last update. function newPosition(positionObject:Object){ var timeNow:Number = getTimer(); var timeDiff:Number = timeNow-lastPositionTime; lastPositionTime = timeNow; // Get new variables from packet var newX = positionObject._x; var newY = positionObject._y; var newRotation = positionObject._rotation; var newSpeed = positionObject.speed; var newXSpeed = Math.cos((_rotation)*Math.PI/180)*newSpeed; var newYSpeed = Math.sin((_rotation)*Math.PI/180)*newSpeed; var newXAcc = (newXSpeed - xSpeed)/timeDiff; var newYAcc = (newYSpeed - ySpeed)/timeDiff; x1 = _x; y1 = _y; x2 = _x+xSpeed; y2 = _y+ySpeed; x3 = newX + (newXSpeed*timeDiff) + (0.5*newXAcc*(timeDiff*timeDiff)); y3 = newY + (newYSpeed*timeDiff) + (0.5*newYAcc*(timeDiff*timeDiff)); x4 = x3 - (newXSpeed + (newXAcc*timeDiff)); y4 = y3 - (newYSpeed + (newYAcc*timeDiff)); A = x4 - (3*x3) + (3*x2) - x1; B = (3*x3) - (6*x2) + (3*x1); C = (3*x2) - (3*x1); D = x1; E = y4 - (3*y3) + (3*y2) - y1; F = (3*y3) - (6*y2) + (3*y1); G = (3*y2) - (3*y1); H = y1; clearInterval(followSplineInterval); currentStep=1; followSplineInterval = setInterval(this, "followSpline", timeDiff/noOfSteps); } function followSpline(){ var t:Number = currentStep/noOfSteps; _x = A*t*3 + B*t*2 + C*t + D; _y = E*t*3 + F*t*3 + G*t + H; currentStep++; if(currentStep==noOfSteps) clearInterval(followSplineInterval); } When executing this code, the oppponent tank moves in an opposite X direction to that expected, and the Y position flips from +ve to -ve by an increasing value. Any help on this would be greatly appreciated. |
||||
|
||||
![]() Rewb0Rn Member since: 2/18/2004 From: Berlin, Germany |
||||
|
|
||||
| Hi, thanks for the great tutorial, really helped me out. Have a question on this: when following the cubic spline, 1) would you still simulate the object? what if it intersects another object while moving, wouldn't that result in random behavior? I use ode and intersection of objects is pretty ugly when talking about network determinism. 2) is it possible to change the target position and velocity while following the spline? Regarding 1), I Have this thought of setting the physical body of an object immediately to the new position but move the visible part on a cubic spline to the position of the body, that of course might change during simulation. Kind Regards, rewb0rn |
||||
|
||||
![]() rvangaal Member since: 3/26/2008 |
||||
|
|
||||
| The article contains some typos it seems. You would say the article has a typo, and Coord3= and Coord4= should be reversed, if you look at the image. Also, the spline is exaggerated when I use a 1 second correction time. I must apply something like 0.333 scaling to the first derivative vector (x0->x1) and 0.666 for the other side. Still searching for the right answer. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|