Scene boundary loop
Hello. Im trying to make a simple game (based on the Shooter tutorial). I want to make the scene 'in loop', like when any object gets to the boundary, it appears on the other side.
I got it working by using ontriggerExit function.
void OnTriggerEnter(Collider other){
Vector3 curP = other.gameObject.transform.position;
other.gameObject.transform.position = new Vector3 (-(curP.x) , curP.y, curP.z);
}
However my problem is: Bullets are spawned in the middle of the rocket, which means that if not all rocked is yet out of the boundary but middle is, shots are already created out of the box and simply fly away(included a picture for better understanding).
I've tried using 4 colliders on each side of screen, but some other problems arise from that (rocket stops at edge and starts to flicker between top and bottom)
Code-wise I could do it the good old way - counting the objects positions in each frame and " if position bigger than max, set position to..." but I feel like there should be a nicer approach,and here I couldn't make use of the unity collision system and would have to 'know' all the objects in game.
Other idea I got would be to use 2 bounding boxes, one slightly bigger(by half of the ship size) that would work for the bullets not caught by the smaller boundary. But this also feels like scratching left ear with right hand.
I've run out of ideas within my current skill. Any idea will be appreciated
[1]: /storage/temp/58520-untitled.png
Your answer
![](https://koobas.hobune.stream/wayback/20220612045823im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Play Sound on TriggerEnter 0 Answers
How to check for a player tag OnTriggerEnter 1 Answer