[ C# ] Restoring position of a player

So i have this code, what I am trying to do is to restore the player to its original position after being hit by an obstacle. When I run the code, it doesn’t work, the collision happens and the player starts to advance indefinitely. And in the console there is nothing displaying about the lines which shows the result of moving the player.

	void Update () {
/*		
        float inputX = Input.GetAxis("Horizontal");
		float inputY = Input.GetAxis("Vertical");
*/
		inputY = Input.GetAxis("Vertical");
 

		if(inputY > 0) spriteRenderer.sprite = biplaneSpriteSheet_1;

		else if(inputY < 0) spriteRenderer.sprite = biplaneSpriteSheet_2;

		else spriteRenderer.sprite = biplaneSpriteSheet_0;

		// this part restore the player to its original position.
		if (inputX < 0) 
		{
			inputX += (Time.time / 100);
			movement.x = inputX;

			Debug.Log(inputX);
		}

		movement = new Vector2(
			speed.x * inputX,
			speed.y * inputY);


		Debug.Log("inputX vale " + inputX);
		Debug.Log (movement.y);
	}

	void FixedUpdate()
	{
		rigidbody2D.velocity = movement;
	}

	void OnCollisionEnter2D(Collision2D collision)
	{
		bool damagePlayer = false;

		// coliding with the obstacles
		EnemieScript enemy = collision.gameObject.GetComponent<EnemieScript>();
		if (enemy != null)
		{
			damagePlayer = true;
                       
                        // hurting the player will make it to stepbackward -1.0f, so the last if in the update() function will restore the position of the player
			movement.x -= 1.0f;

		}
		
		// Hurt player
		if (damagePlayer)
		{
			Salud playerHealth = this.GetComponent<Salud>();
			if (playerHealth != null) playerHealth.Damage(1);
		}

	}


}

Any help would be appreciated

movement.x -= 1.0f; in line 49 will change nothing relative to your condition in line 16.
Maybe you wanted to put inputX there instead of movement.x …

Done it, but the same result… maybe a spawnpoint can do the job???

Then you’re inputX might be greater than 1 in the beginning?! Does any other script alter the value of it?
Also, i can only see that you’re calcutlating the movement with it but never set any position AND as soon as you set a new value to movement.x, you simply create a new Vector2 which overrides the value again.

Try to Debug.Log your values a bit more to see what’s working, what’s not. According to the values being logged you will probably be able to find out what’s wrong with the logic in there.

inputX is always zero and then when I add value for InputX I get from the Log -1 but it seems that line 49 repeats indefinitely, because line 21 never shows the debug log message…