This question was
closed Feb 14, 2017 at 02:09 AM by
Bill9009.
Question by
Bill9009 · Feb 02, 2017 at 03:06 PM ·
collider2dtransform.position
Colliders not working
I'm not sure whats happening. When my player collider comes into contact with my boundary colliders it doesn't teleport , the player, to the other edge of the screen.
public class boundaries : MonoBehaviour {
public Transform player;
void OnCollisionEnter2D(Collision2D coll)
{
player.position = new Vector2(player.position.x * -1, player.position.y * -1);
}
}
Comment
Answer by djremiks · Feb 02, 2017 at 05:06 PM
Do you have correctly used the good type of colliders. Are you sure you do not have to use trigger instead?
Answer by Bill9009 · Feb 03, 2017 at 12:25 AM
What do you mean good type of colliders? I am using a capsule collider 2d on the player and edge colliders 2d for the boundaries. I tried onTriggerEnter2d but it did not work. This is the script with onTriggerEnter2D.
public class boundaries : MonoBehaviour {
public Transform player;
void OnTriggerEnter2D(Collider2D other)
{
player.position = new Vector2(player.position.x * -1, player.position.y * -1);
}
}