void UpdateInputTimeStamp() { if (DistanceTracker > TimeStampDistance) { DistanceTracker = 0; Scr_PositionTimeStamp TimeStamp = new Scr_PositionTimeStamp(Time.time, transform.position); PositionTimeStamps.Insert(0, TimeStamp); if (PositionTimeStamps.Count > MaxTimeStamps) { PositionTimeStamps.RemoveAt(MaxTimeStamps); } } }
void Start() { rb = GetComponent <Rigidbody>(); PreviousPosition = transform.position; CharacterCollider = GetComponent <CapsuleCollider>(); //Put an initial entry into the position time stamps Scr_PositionTimeStamp TimeStamp = new Scr_PositionTimeStamp(Time.time, transform.position); PositionTimeStamps.Insert(0, TimeStamp); //Adds the initial acceleratoin to the list AccelerationHistory.Insert(0, CurrentAccelerationPercentage); //Set the floor object UpdateTransformParenting(); //Set the previous floor object PreviousFloorObject = FloorObject; }
void UpdateFollowPosition() { if (Leader != null) { #region Distance Detachment //If they are on a moveable block if (Leader.transform.parent.GetComponent <Scr_Block_Movable>() != null) { //And they are too far away float distance = (transform.position - Leader.transform.position).magnitude; //If they are too far away if (distance > UnPartyDistance) { //Break up the party Scr_PlayerController.inst.SeperateCharacter(Scr_PlayerController.inst.GetPartyIndex(this)); //Get out of the Follow function, now that you dont have a leadrr return; } } #endregion //Gets the oldest TimeStamp from the leader and sets it to the target Scr_PositionTimeStamp TargetTimeStamp = Scr_PlayerController.inst.GetPositionTimeStampFromCharacter(Leader); //Set the target rotation TargetRotation = Quaternion.LookRotation(TargetTimeStamp.Position - transform.position); #region Keep Upright //Change to euler Vector3 EulerRotation = TargetRotation.eulerAngles; //Reset X and Z rotations (keep them standing upright) EulerRotation.x = 0; EulerRotation.z = 0; //Revert back to quaternion TargetRotation = Quaternion.Euler(EulerRotation); #endregion //Update the target position TargetPosition = TargetTimeStamp.Position; #region Simulated Acceleration //Simulated Acceleration //If you are holind down a movement then use the archived acceleration CurrentAccelerationPercentage = Leader.AccelerationHistory[Leader.AccelerationHistory.Count - 1]; //Update Acceleration //CurrentAccelerationPercentage = Leader.CurrentAccelerationPercentage; #endregion //Update Rotation transform.rotation = Quaternion.RotateTowards(transform.rotation, TargetRotation, ((360 / TurnTime) * Time.deltaTime)); //Update Position //This bit is intentional, as it scales the follow speed based on the distance to the target point //Determine the full vector Vector3 FollowVector = (TargetPosition - transform.position) * RunSpeed * CurrentAccelerationPercentage; //Determine the magnitude float FollowVectorMagnitude = Mathf.Clamp(FollowVector.magnitude, 0, MaxFollowSpeed); //Clamp the magnitude FollowVector = FollowVector.normalized * FollowVectorMagnitude * Time.deltaTime; //Normalize and reapply new magnatude transform.position += FollowVector; } //If you dont have a leader, slow down consistently still else { //update Decelration CurrentAccelerationPercentage = Mathf.Clamp01(CurrentAccelerationPercentage - (DecelerationSpeed * Time.deltaTime)); //Move the character forward based on rotation transform.position += transform.forward * RunSpeed * CurrentAccelerationPercentage * Time.deltaTime; } }