My platformer game has a mechanic with the floor is lava and when you touch it you “respawn” back to the start, i have an empty game object called respawn but cant figure out how to teleport to it?
what i have:
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Lava")
{
new Vector3(-5.51, 2.03, 0);
}
}
So instead of the new Vector3
, I believe you could use something much simpler.
at the top you make a public Transform
and call it transformTo
. Then in the
if (col.GameObject.name == "Lava"){
transform.position = transformTo.position;
}
Also, I only work in 2D, but I believe it works both ways. If the collisions aren’t registering then you could switch to void OnTriggerEnter
and then say
if(collision.tag == "Lava"){
transform.position = transformTo.position;
}
Then change the lava collider to be an Is Trigger
in the editor.
P.S If you’re wanting to check if you’re even registering that you’re hitting an object you could try Debug.Log("I hit it!")
;
I hope you found this helpful!