Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Boxcollider is Triggering but not spawning the Background

Discussion in 'Physics' started by xhasaanx, Feb 13, 2015.

  1. xhasaanx

    xhasaanx

    Joined:
    Feb 8, 2015
    Posts:
    1
    Dear Members,

    what i want to do is, that a BoxCollider detects the Background, and spawns it to the Front so basically the Background will become Infinite. It is working in the case of detecting the Background, but the Collider is only pulling the Background with the Moving Camera, not moving it to the Place, before the Camera reaches. (Which i wanna do, because you shouldnt see the objects jumping around.

    The main Camera Follows my Character.
    The main Camera has a EmptyObjects, which is a few centimetres behind the camera. the Empty detecs the Background and should Spawn them In front of the Camera with a Script, written in C.

    Heres the Script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BGLooper : MonoBehaviour {
    5.  
    6.         int numBGPanels = 5;
    7.  
    8.         void OnTriggerStay(Collider collider) { // Look at here
    9. Debug.Log("Hit! Obj: "+collider.gameObject.name);
    10.  
    11.  
    12.         float withOfBGObject =((BoxCollider)collider).size.x;
    13.        
    14.         Vector3 pos = collider.transform.position;
    15.                
    16.         pos.x += withOfBGObject * numBGPanels ;
    17.        
    18.         collider.transform.position = pos;
    19.        
    20.         }
    21. }
    Is the Mistake in my Logical Thoughts? Because theres a Video on youtube, where it is working:




    I would apprichiate any help. thanks in advance
     
  2. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,006
    1. What type of collider is on your detection object and what are its dimensions?
    2. What value are you getting for withOfBGObject?
    3. How many units ahead of your camera do you wish to place the BG object?

    This information might shed some light on what is going wrong.

    William