private void UpdateBallDirAndSpeed(float ticksToTravel) { if (mNumTicksLeft <= 0) // beginning of a new road { mNumTicksLeft = ticksToTravel; } // use num ticks to determine how far we have travelled float percentTravelled = (ticksToTravel - mNumTicksLeft) / ticksToTravel; // ball's center position should be percentTravelled along the road's entire length float roadLength = mRoad.RoadSegmentLength(mCurrentRoadSegment); Vector2 v = mRoad.RoadSegmentDir(mCurrentRoadSegment); Vector2 startPos = mRoad.RoadSegmentStartPos(mCurrentRoadSegment); Center = startPos + percentTravelled * roadLength * v; VelocityDirection = v; // speed will be a function of what is remaining length and remaining ticks left. float totalLength = mRoad.RoadSegmentLength(mCurrentRoadSegment); float travelled = (Center - startPos).Length(); float remainLength = totalLength - travelled; Speed = remainLength / mNumTicksLeft; }
private void UpdateBallDirAndSpeed(float ticksToTravel) { // Figure out how much we have travelled Vector2 startPos = mRoad.RoadSegmentStartPos(mCurrentRoadSegment); Vector2 dir = startPos - Center; float travelled = dir.Length(); // Figure the current direction of the road Vector2 v = mRoad.RoadSegmentDir(mCurrentRoadSegment); // Our ball should be travelled along the road direction Center = startPos + travelled * v; VelocityDirection = v; // speed will be a function of what is remaining length and remaining ticks left. float totalLength = mRoad.RoadSegmentLength(mCurrentRoadSegment); float remainLength = totalLength - travelled; float percentLeft = remainLength / totalLength; float ticksLeft = ticksToTravel * percentLeft; Speed = remainLength / ticksLeft; }