player.transform.position not working.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class lavaDeath : MonoBehaviour
{

    public GameObject player;
    // Start is called before the first frame update
    void Start()
    {

    }
    // Update is called once per frame
    void Update()
    {
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.name == "Quad" || other.gameObject.tag == "Player")
        {
            Debug.Log("true");
            player.transform.position = new Vector3(14f, 1f, -25f);
        }
    }
}

a simple script but my character doesn’t get teleported every time, only like 20% of the time. no, it’s not a child, it’s a parent. i have no idea what’s going on, any ideas? and yes, I am getting input in the console from the debug.log command.

So, even when the player doesn’t get reset, the Debug message triggers?

What kind of collider does the lava have? Is it a mesh collider on a quad? it’s possible your player is going too fast and moving right through your lava.

Thanks for your responses, I fixed it. The trick was to disable the playerController on touch and then, with an empty object at spawn, reenable it by scripting a collision with that empty object.

1 Like