stop Addforce

Okay, I have a player that bounces off a tagged object on trigger, using Addforce. the force is set to *300, causing my player to get knocked back, which continuously move . So I placed a cube with a 2D box collider attached to it to stop the player from moving too far. My question is: how can I implement the Addforce to only move a short amount of distance, OR have a timer that stops Addforce after the trigger event occurred. Can someone help me with this. Thank you! this is my script:

     using UnityEngine;

     using System.Collections;

     public class Moveplayer : MonoBehaviour {

		
void OnTriggerEnter2D(Collider2D other) 
{
	if (other.tag == "Bouncy object")
		GetComponent<Rigidbody2D>().AddForce(transform.right * 300);
	GetComponent<Rigidbody2D>().AddForce(transform.right * 300);

      }
 }

You could use

GetComponent<RigidBody2D>().AddForce(transform.right * 300, ForceMode.Impulse);

This will add a non-continuous force to the object which will stop moving as long as there is some drag set on the rigidbody. It will also be a little weaker so you may have to tweak the size of the force.

Also as a side note if you are using Rigidbody2D a lot in that script you might just want to create a field for it and assigning it inside that Start() method that way you don’t have to get the component constantly which will give you a performance hit in the long run. Of course, if it is just for that one trigger event it should be all good.