Search Unity

Raycast wont hit animated collider (mecanim)

Discussion in 'Editor & General Support' started by TheAMes, Oct 24, 2013.

  1. TheAMes

    TheAMes

    Joined:
    Jun 17, 2013
    Posts:
    23
    Ok so I've been battling with this for a few days now and have had to resort to asking for help.

    I am using standard raycast from the camera position through mouse position to apply a small impulse to a collider/rigid body when it's clicked. Not my overall goal more of a test.

    This works fine if I drop a simple cube in to my scene.

    Now I add a 3d character, I have tried both an export from DAZ 3D and also the Robot on the Unity mecanim tutorial, results are the same for both.

    I apply humanoid animations, create a simple animator controller, set an idle animation, so far so good, the robot stands there doing the idle animation.

    I click on him and no raycast is hit, obviously cause I have no colliders. So I go ahead and create a ragdoll for the robot, this creates all the colliders etc yet clicking on the locations of these colliders they are never hit, the raycast just reports that it hit the ground plane

    If during run time i disable the animator the robot collapses to the floor using physics and the ragdoll (this is my overall aim, he gets shot and animator is switched off etc) and he lies there on the floor. If I now click on his body parts it hits correctly, impulses are applied to the individual colliders nicely

    I understand that I wouldnt be able to apply an impulse to the collider during an animation as it would have no effect, what I am confused about is why won't the ray cast collide with these colliders?

    I thought possibly it was my raycast at fault, but if I import the UFPS package the bullets will not collide with the colliders during an animation, they hit the floor behind him, if I disable the animator the bullets hit the colliders as expected

    Any info here would really be appreciated as its been a few days now, I'm quite new to Unity too

    Thank you
     
  2. RAWilco

    RAWilco

    Joined:
    Oct 7, 2013
    Posts:
    7
    I realise that this is an old thread and I'm sorry I can't be more helpful, but I seem to be having this problem as well.

    Strangely though, I can actually get my mecanim animated ragdolls to collide with the raycast, but for some reason it only seems to happen occasionally. It's almost as if the colliders are not actually in the place where the editor window shows them to be, as if they are offset for some reason. So while it appears that the raycast is passing through the colliders, nothing happens because it is just hitting empty space. But if you then fire off the raycast at random positions in the area around where the collider appears to be, it does sometimes recognise the collision.

    I'm really puzzled by this. Could it be related to FixedUpdate or Update? Is it a bug in Unity? Or am I just missing something blindingly obvious? Any advice would of course be muchly appreciated.
     
  3. warpspasm

    warpspasm

    Joined:
    Apr 21, 2014
    Posts:
    6
    I'm having this exact same problem! Has anybody figured out a solution for this yet? Please let me know, I'm completely stumped by this problem right now!

    It feels like unity is broken in some way or I'm just really coding something wrong. Thanks
     
  4. cloudcamaleoniv

    cloudcamaleoniv

    Joined:
    May 17, 2013
    Posts:
    57
    Thank god I'm not the only one. This is also happening to me.

    I'm not using mecanim though. I'm using a simple script that rotates a cube (with a collider) while some outside object keeps firing raycasts at it.

    Using the "Pause" with "NextFrame" buttons of the editor and drawing the rays each frame, it's very clear that, after the cubes rotates, some raycasts don't hit it.
     
    Last edited: Aug 24, 2014
  5. phillmorgan86

    phillmorgan86

    Joined:
    Sep 3, 2014
    Posts:
    3
    I am also having this problem! I have found that if I change the rigid bodies to kinematic, the issue corrects itself and raycasts hit the colliders again 100% of the time. I have also discovered that, during play mode, if you disable and enable Animate Physics on the animator component, the problem "sometimes" corrects itself. Its like giving the animator a nudge to catch up with the physics engine :S
     
  6. Killutch

    Killutch

    Joined:
    Dec 17, 2014
    Posts:
    2
    Oh my gosh this is the same problem I'm having. I've been messing around with it for hours and narrowed it down to the Animator component :(. I tried making different animations but still got the same result when using Raycast. Hopfully someone comes up with a good solution. I'm going to have to program the functionality I need another way I guess.
     
  7. Killutch

    Killutch

    Joined:
    Dec 17, 2014
    Posts:
    2
    So I solved my issue but I'm not sure its the same as everyone else's

    Problem Cause:
    Was disabling and Distroying object via a OnMouseDown and also trying to use ray casting to check what Item it was around the same time. For what ever reason it would seem that the animation on the object expedites the destruction and or OnMouseDown making the object gone before the ray cast could test the collider

    Solution I Used:
    simply called a disable and object destruction from the ray cast detected item and deleted the OnMouseDown crap.

    I feel a little dumb that this took me so long to find out but everything seemed to point to the animator because my code would work fine if there was no animator.