Search Unity

How to use mouse to choose a scaled GameObject

Discussion in 'Physics' started by 15041726648, Sep 24, 2017.

  1. 15041726648

    15041726648

    Joined:
    Mar 26, 2015
    Posts:
    6
    In my project,actually i use kinect to perform zoom,but i have completed zoom.
    This is not the reason why i cann't choose gameobject.
    First,i need to scale GameObject,and i change localscale for scaling GameObject.
    The code is like this:
    Vector3 newLocalScale = new Vector3(zoomFactor, zoomFactor, zoomFactor);
    transform.localScale = Vector3.Lerp(transform.localScale, newLocalScale, spinSpeed * Time.deltaTime);


    Second,after i scaling the GameObject,i found that i cann't choose the GameObject with mouse,The project uses bounds.IntersectRay for hitting gameobject.

    Before zooming i can choose any gameobject with mouse,so i think the problem must be about localscale ,bounds or collider.

    Third,i debug gameobect's bounds and collider before and after zooming,and i also found that the scaled GameObject's bounds and collider size are both not changed.


    Who can help me solve this problem? Thank you very much
     
    Last edited: Sep 26, 2017
  2. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    You may need to also scale up the Collider for the object.
     
    karl_jones likes this.
  3. 15041726648

    15041726648

    Joined:
    Mar 26, 2015
    Posts:
    6
    Thanks a lot,i'll try it.
     
  4. 15041726648

    15041726648

    Joined:
    Mar 26, 2015
    Posts:
    6
    I wonder how can i scale collider,could you please tell me the details
     
  5. 15041726648

    15041726648

    Joined:
    Mar 26, 2015
    Posts:
    6
    i have tested ,before and after zooming bounds and collider are both not changed
     
  6. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    Is it necessary to adjust localScale and not simply scale?
    Looking back on the documentation, the colliders are sized to fit the gameObject's scale.

    What kind of collider are you using?
     
  7. 15041726648

    15041726648

    Joined:
    Mar 26, 2015
    Posts:
    6
    In the demo project,use Box Collider.i've not found collider of the developing project where it is.
     
  8. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    Okay, I made a short script to test scaling of an object and the collider's response to it.
    When scaling a basic cube (with BoxCollider) through use of transform.localScale (just like your script), the collider scaled as necessary.

    Can you perhaps post screenshots demonstrating the misaligned collider before and after scaling?
    Also, a more complete copy of the code you're using would help with spotting any logical errors.