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)
{
// check de “tag”
if(other.gameObject.tag == “enemy”)
{
ResetPlayer();
}
}
function ResetPlayer()
{
// reset de positie van de “player”
transform.position.x = -8;
transform.position.y = 0;
}
also, how exactly does your player move?
If it follows the mouse as the mouse is moving then trying to change the position will be a problem (as you’ve discovered)
using the mouse position to move the player doesn’t seem like a good design choice (to me anyway).
You could maybe make the player move towards the cursor only when the mouse is clicked?
You are updating the player’s position to mouse position every frame. The resetplayer function works, but the very next frame, the player moves to where the mouse is.
A good solution is to move the player only when clicked, that way the resetplayer has a chance to work.