Search Unity

3d-studio-max model is invisible for RayCast

Discussion in 'Getting Started' started by IvanDonets, Feb 23, 2016.

  1. IvanDonets

    IvanDonets

    Joined:
    Feb 19, 2014
    Posts:
    117
    I loaded into unity3d a 3ds (3d studio max) file (it is a statue), but when it is placed on the terrain and mouse is over it, raycast doesn't hit the model. why? I applied to it rigidbody and collider components, and default blank monodevelop script (just in case, to make it visible as monodevelop object which can be destroyed etc), but RayCast still doesn't work.

    My code is attached.
    The problem is with CheckObjectUnderMouseCursor function here:
    Code (CSharp):
    1.  ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    2.         RaycastHit[] hits = Physics.RaycastAll (ray);
    3.  
    4.         foreach (RaycastHit hit in hits)
    5. {
    6. ObjectUnderCursor = hit.transform.gameObject.name;
    7. if (ObjectUnderCursor == "Krishna")
    8. {
    9.                 Debug.Log (ObjectUnderCursor);
    10. }
    11. }
    I named the loaded 3ds-max statue as "Krishna", and it should be detected just like Terrain, Potion or Enemy is detected after mouseOver, but that doesn't happen (Debug.Log doesn't print anything).
    I expect to load different similar static 3d objects and make them detectable by Raycast.
     

    Attached Files:

  2. IvanDonets

    IvanDonets

    Joined:
    Feb 19, 2014
    Posts:
    117
    Sorry, I solved the problem. It was with the collider. I set new capsule collider and now it is detectible by raycast
     
    marcel-me and JoeStrout like this.