- Home /
Raycast occasionally won't hit colliders on Mecanim animated characters (but hits perfectly if Animator is disabled)
I have a a fairly simple setup that involves a Raycast being fired from the Main Camera (attached to an FPS Controller) every time the Left Mouse Button is clicked. When this Raycast hits a collider with a rigidbody, it applies a force on the rigidbody in the direction that the camera is facing. All of this works perfectly on stationary game objects and rag dolls.
However, if the Raycast is fired at a character that is being animated using a Mecanim animator, it becomes very unreliable.
Here's a screenshot of what I'm talking about:
The yellow debug line proves that the Raycast is definitely hitting the character's head collider, but Unity thinks that it is actually hitting the wall behind him. The weird thing is though, if I keep the Raycast in exactly this position but repeatedly fire it off over and over again, Unity will occasionally recognise that the Raycast is indeed hitting the head collider, but most of the time it just seems to ignore it. It's almost as iff the collider is flickering in and out of existence. And what's even weirder is, if I turn off the Animator so that the character flops down into a rag doll, the Raycast hits his colliders 100% of the time.
From this I've gathered that there must be no problems with the Raycast, and since all of the objects are on the same layer (and definitely not on the Ignore Raycast layer), then there must be an issue with the Mecanim system somewhere. I've tried fiddling with the Animator's Update Mode, but the same issue occurs regardless of whether this is set to Normal, Animate Physics or Unscaled Time.
Any advice on how I might be able to solve this would be muchly appreciated.
Is this an issue with the latest update of unity? Because I'm just seeing this exact same problem today. And I mean exactly the same, I can't figure it out!
Does anyone have any ideas how to fix this?
I am also having this exact same problem.
I think it has to do with the Animator Controller because disabling it on my character causes the raycast to hit the colliders accurately 100% of the time. Characters using an Animation component also have 100% accurate colliders.
Does anyone have anything to share about this? I've been searching for days and I can't find anything.
I believe I've found the sollution to my issue. The character whose colliders were ignoring the raycast I was using also had a third party I$$anonymous$$ asset attached to it. Raycasts would sometimes ignore the colliders because they were being fired before the I$$anonymous$$ updated. Setting my raycasts to fire in FixedUpdate ins$$anonymous$$d of Update seems to have fixed the issue. I would suggest other people having a similar problem check to see when their raycasts are being fired.
Answer by Wiseman17 · Mar 22, 2015 at 11:08 PM
As the topic caster answere himself in a parallel branch: http://hutonggames.com/playmakerforum/index.php?topic=7856.0, working solution might by to turn on "Is Kinematic" for any rigidbody attached to the animated model. Worked perfectly for me.
Ah damn, sorry about that. This thread had completely slipped my $$anonymous$$d. Thanks for closing it off.
No problem RAWilco. Thank YOU for the good question and answer ;)