public void ProcessMovement() { if (Actor != null && settings.isActive) { // Smooth input buffer. #region Smooth input. newInput = movement.Sum().x; if (GetBufferSize(settings.inputSmooth) != smoothBuffer.bufferSize) { smoothBuffer = new ValueBuffer(GetBufferSize(settings.inputSmooth), true); } smoothBuffer.Add(newInput, 0, 0); moved = smoothBuffer.Average().x; #endregion // Gain if (moved > 0) { moved *= settings.gain.forward; } else { moved *= settings.gain.backward; } // Current position. pos = Actor.transform.position; newRot = Actor.transform.rotation; #region No Path. if (path == null) { pos[2] = pos[2] + (moved); } #endregion #region With Path else { float currentDist = path.path.GetClosestDistanceAlongPath(pos); // more dynamic. float newDist = moved + currentDist; // set path looping. if (settings.loopPath) { endofPath = PathCreation.EndOfPathInstruction.Loop; } else { endofPath = PathCreation.EndOfPathInstruction.Stop; } // calculate position and heading. pos = path.path.GetPointAtDistance(newDist, endofPath); pathRot = path.path.GetRotationAtDistance(newDist, endofPath).eulerAngles; pathRot[2] = 0; newRot = Quaternion.Euler(pathRot); } #endregion //update position. if (Actor.isActive) { Actor.transform.position = pos; Actor.transform.rotation = newRot; } } // log. if (settings.enableLogging && settings.isActive) { // Log raw input controller. logMsg.name = name; logMsg.move = (int)(movement.Sum().x * 1000); logger.logFile.Log("Linear Controller", logMsg); } // Clear buffer. movement.Clear(); }
public void SetPath(PathCreation.VertexPath newPath, PathCreation.EndOfPathInstruction eopi) { myPath = newPath; myEndOfPathInstruction = eopi; }