Respawn in Frogger

Hello,

i started creating my first game with unity. I try to build Frogger.

My Problem is, that when a car hits the Frog, he jumps to the spawn point only for the time, when the collider of the car is over the collider of the frog. When the car passed, the frog in on the “old” position.

Part of Frog Script:

public Vector3 respawnPoint;

void OnTriggerEnter2D (Collider2D col)
if (col.gameObject.tag == "Car")
        {
          Debug.Log("You Lost");
           Life -= 1;
          
            transform.position = respawnPoint;
        }

Anybody an idea of fixing this problem?

Hi,

What code you have in the Update() loop?

maybe there is some position variable, that is not resetted on the collision…?

I am not sure if anybody can understand this but this is my Update()

void FixedUpdate() {


        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        animUsed = 0;


        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            transform.parent = null;
            float right = 0.5f;
            newPosition = rb.position + Vector2.right * right;
            newPosition.x = Mathf.Clamp(newPosition.x, -mapWidh, mapWidh);


            transform.localRotation = Quaternion.Euler(0, 0, 90);
            JumpMeth();
            Asourcejump.Play();
          

        }

        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            transform.parent = null;
            float left = 0.5f;
            newPosition = rb.position + Vector2.left * left;
            newPosition.x = Mathf.Clamp(newPosition.x, -mapWidh, mapWidh);

          
            transform.localRotation = Quaternion.Euler(0, 0, -90);
            JumpMeth();
            Asourcejump.Play();
          

        }
      
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            transform.parent = null;
            float y = (Input.GetAxis("Horizontal")) + Spur;
            newPosition = rb.position + Vector2.up * y;
            newPosition.y = Mathf.Clamp(newPosition.y, 0, mapHigh);


            transform.localRotation = Quaternion.Euler(0, 0, 180);
            JumpMeth();
            Asourcejump.Play();
        }

        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            float y = (Input.GetAxis("Horizontal")) + Spur;
            newPosition = rb.position + Vector2.down * y;
            newPosition.y = Mathf.Clamp(newPosition.y, 0, mapHigh);


            transform.localRotation = Quaternion.Euler(0, 0, 360);
            JumpMeth();
            Asourcejump.Play();

        }
        rb.MovePosition(newPosition);

        if (Leben <= 0)
        {
            EndGame();
        }
    }

you are moving transform and in fixedupdate using rigidbody position,
so probably rb doesn’t get moved fast enough…

try moving rigidbody directly instead:

*also, can use code tags, so its easier to see script

thanky you for your fast reply.

I tried using only moving by rigidbody and moving only by transform but both doesn’t work.

When I move the Frog in the time he is on the spawn point, he is not teleported back when the car passed.

Any other ideas?