reset the "player" after collision with the "enemy"

i want to reset the “player” after collision with the “enemy”
The player is moved by mouse.
After the collision, my “player” is moved to the position of the function “Resetplayer” but does not stay there.
It jumps back to the mouseposition.
How can i prevent this?

This is the code i use

var myCamera : Camera;
var vec : Vector2;

function FixedUpdate ()
{
vec = myCamera.ScreenToWorldPoint(Input.mousePosition);
transform.position = vec;
}
function OnTriggerEnter2D(other : Collider2D)
{
if(other.gameObject.tag == “enemy”)
{
ResetPlayer();
}
}
function ResetPlayer()
{
// reset de positie van de “player”
transform.position.x = -8;
transform.position.y = 0;
}

You need to take one boolean variable :

like

var follow : bool = true;

 function FixedUpdate () 
 { 
      if(folllow)
      {
        vec = myCamera.ScreenToWorldPoint(Input.mousePosition); 
        transform.position = vec; 
      }
 }  

 function OnTriggerEnter2D(other : Collider2D) 
 { 
       if(other.gameObject.tag == "enemy") 
       { 
              follow = false;
             ResetPlayer(); 
            
       } 
 }

Thanks.

Its because you are setting your player position to be = to the mouse position in the fixe update method which is called continuously.

Your culprit:

FixedUpdate () 
{ 
   vec = myCamera.ScreenToWorldPoint(Input.mousePosition);
   transform.position = vec;
} 

Proposed solution;

add this field to the class

bool dead = false;

FixedUpdate () 
{ 
   if(!dead)
   {
    vec = myCamera.ScreenToWorldPoint(Input.mousePosition);
    transform.position = vec;
   }
} 
Void OnTriggerEnter2D()
{
   if(other.gameObject.tag == "enemy") 
   { 
     dead = true;
     ResetPlayer();
   }
}