<commit_before>﻿using UnityEngine;
using System.Collections;

namespace MultiPacMan.Player
{
	enum NetworkingOptions {
		Default,
		Interpolation,
		InterpolationAndExtrapolation
	};

	public class NetworkedMovementController : MovementController {

		[SerializeField]
		private NetworkingOptions option = NetworkingOptions.Default;

		private float t = 0.0f;
		private float timeWaited = 0.0f;
		private Vector2 newPosition = Vector2.zero;

		private bool started = false;

		public override void OnStart() {
			newPosition = this.transform.root.position;
			started = true;
		}

		public void UpdatePosition(Vector2 position, Vector2 velocity) {
			switch (option) {
			case NetworkingOptions.Interpolation:
				MoveWithInterpolation(position, velocity);
				break;
			case NetworkingOptions.InterpolationAndExtrapolation:
				MoveWithExtrapolation(position, velocity);
				break;
			default:
				Move(position);
				break;
			}
		}

		private void MoveWithInterpolation(Vector2 position, Vector2 velocity) {
			timeWaited = t;
			newPosition = position;
			t = 0.0f;
		}

		private void MoveWithExtrapolation(Vector2 position, Vector2 velocity) {
			timeWaited = t;
			newPosition = position + timeWaited*velocity;
			t = 0.0f;
		}

		private void Move(Vector2 position) {
			rb.MovePosition(position);
		}

		void FixedUpdate() {
			if (!started || option == NetworkingOptions.Default) {
				t = 0.0f;
				timeWaited = 0.0f;
				newPosition = Vector2.zero;
				return;
			}

			t += Time.deltaTime;
			rb.MovePosition(Vector2.Lerp(rb.position, newPosition, t/timeWaited));
		}
	}
}<commit_msg>Fixing Networked Movement old position calculation<commit_after>﻿using UnityEngine;
using System.Collections;

namespace MultiPacMan.Player
{
	enum NetworkingOptions {
		Default,
		Interpolation,
		InterpolationAndExtrapolation
	};

	public class NetworkedMovementController : MovementController {

		[SerializeField]
		private NetworkingOptions option = NetworkingOptions.Default;

		private float t = 0.0f;
		private float timeWaited = 0.0f;
		private Vector2 newPosition = Vector2.zero;
		private Vector2 oldPosition = Vector2.zero;

		private bool started = false;

		public override void OnStart() {
			newPosition = this.transform.root.position;
			started = true;
		}

		public void UpdatePosition(Vector2 position, Vector2 velocity) {
			switch (option) {
			case NetworkingOptions.Interpolation:
				MoveWithInterpolation(position, velocity);
				break;
			case NetworkingOptions.InterpolationAndExtrapolation:
				MoveWithExtrapolation(position, velocity);
				break;
			default:
				Move(position);
				break;
			}
		}

		private void MoveWithInterpolation(Vector2 position, Vector2 velocity) {
			timeWaited = t;
			oldPosition = rb.position;
			newPosition = position;
			t = 0.0f;
		}

		private void MoveWithExtrapolation(Vector2 position, Vector2 velocity) {
			timeWaited = t;
			oldPosition = rb.position;
			newPosition = position + timeWaited*velocity;
			t = 0.0f;
		}

		private void Move(Vector2 position) {
			rb.MovePosition(position);
		}

		void Update() {
			if (!started || option == NetworkingOptions.Default) {
				t = 0.0f;
				timeWaited = 0.0f;
				newPosition = Vector2.zero;
				return;
			}

			t += Time.deltaTime;
			rb.MovePosition(Vector2.Lerp(oldPosition, newPosition, t/timeWaited));
		}
	}
}
{'fraction_non_alphanumeric': 0.09003601440576231, 'fraction_numerical': 0.014405762304921969, 'mean_word_length': 3.851528384279476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4559073', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1019, 'n_words': 239}