navmeshagent position issue

23 views
Skip to first unread message

jazzj2

unread,
Feb 21, 2017, 7:03:22 AM2/21/17
to Developer Support
i've got a gameobject with a navmeshagent component
the ragdoll and animated characters are parented to it
when the ragdoll enters a full ragdoll state, it usually ends up going further away from the original position of the navmeshagent
i want the navmeshagent to always be close to the ragdoll
so i did this in LateUpdate()
        if (state == CharState.ragdoll)
        {
            Vector3 temp = Ragdoll.position;
            pos.position = temp;
            Ragdoll.position =temp;
        }
the navmeshagent is teleported to the ragdoll's position, while the ragdoll doesn't move
however, the ragdoll doesn't seem to stay where it was before the navmeshagent teleported
and in the next frame, the navmeshagent moves to the now moved ragdoll, and so the whole thing slowly moves away from where it's supposed to be, instead of stopping after all the physic forces slowly die out.
i tried different things, turned off the navmeshagent, lerped rather than directly porting, i always get poor results

jazzj2

unread,
Feb 21, 2017, 7:03:44 AM2/21/17
to Developer Support
for the record, i'm using unity 5.3.0

jazzj2

unread,
Feb 21, 2017, 8:37:15 AM2/21/17
to Developer Support
and with further testing, i can more or less get around this, but the main issue now is that when the ragdoll ends and the get up animations start, the humanoid ragdoll animator starts the body from where it was when it entered the ragdoll, not where it currently is
is there any way i can set where the animated body is supposed to start from?
right now, i'm already setting it's localPosition to Vector3.zero, but clearly that's not enough
    protected virtual void LateUpdate()
    {
        //unrelated
        anim.SetFloat("movX", InputX, 0.1f, Time.deltaTime);
        anim.SetFloat("movY", InputY, 0.1f, Time.deltaTime);

        //for the record, Ragdoll is actually the hips/pelvis
        Animated.localPosition = Vector3.zero;
        Animated.localRotation = Quaternion.identity;
        if (state == CharState.ragdoll)
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                Vector3 temp = Ragdoll.position;
                pos.position = temp;
                Ragdoll.position = temp;
                Quaternion rot = Ragdoll.rotation;
                pos.rotation = Quaternion.LookRotation((Head.position - Ragdoll.position) * (anim.GetBool("Name Hash") ? -1 : 1));
                Ragdoll.rotation = rot;
                anim.SetBool("Full Hierarchy Ragdoll", false);
            }
            nav.enabled = false;
        }
        else
        {
            nav.enabled = true;
        }
    }


jazzj2

unread,
Feb 21, 2017, 8:38:06 AM2/21/17
to Developer Support
and i forgot to post the example
rpg2bug.mp4

Developer Support

unread,
Feb 21, 2017, 4:07:39 PM2/21/17
to Developer Support
It's hard to say exactly without seeing a project, but from your original post it sounds like your hierarchy looks like this:
  • NavMeshAgent
    • Ragdoll
    • RagdollAnimator
Is this correct? If so, you should instead put the NavMeshAgent on the same GameObject as the RagdollAnimator. You should also probably set NavMeshAgent.enabled = false in a callback you register with RagdollAnimator.OnEnterFullHierarchyRagdoll, and respectively set NavMeshAgent.enabled = true in a callback you register with RagdollAnimator.OnExitFullHierarchyRagdoll. Both of these can be done via the inspector or via code. Beyond that, I don't know the NavMeshAgent APIs very well, so it is possible you may have to call Stop when it enters full hierarchy ragdoll, and/or Resume or Warp or similar when it exits.

jazzj2

unread,
Feb 22, 2017, 4:05:53 AM2/22/17
to Developer Support
alright, that fixes my issue
i've got another problem though, unrelated to that
limbs bend incorrectly
this is the character trying to punch with the left arm, but the elbow/forearm seems to bend way past it's limit

i used to think this is an issue with setting up the ragdoll outside of the t-pose, but that's definitely not the case this time

jazzj2

unread,
Feb 22, 2017, 4:56:28 AM2/22/17
to Developer Support
and another thing
now that the navmeshagent is on the Animated character, when he moves, the ragdoll stutters behind
if i do (in LateUpdate)

            ragdoll.position = animated.position;
            ragdoll.rotation = animated.rotation;
things work smoothly while animating, but if i go into a full body ragdoll, and then come out of it, i get the earlier issue with getting up from a full hierarchy ragdoll state
i tried adding some conditions to the ragdoll positions, but simply having it there and not having it in some states, ensures that the character is gonna teleport at some point in time
in the best case scenario, i'm doing

if (state != CharState.ragdoll && state != CharState.gettingup)
        {
            ragdoll.position = animated.position;
            ragdoll.rotation = animated.rotation;
        }
in which case i can only see the character teleporting back and forth for a frame or two right after he finishes getting up
nostutterbutteleport.mp4
stutterbutnoteleport.mp4

Developer Support

unread,
Feb 26, 2017, 11:06:05 AM2/26/17
to Developer Support
Hi again! I'm at GDC this week so may be a bit slow to respond. Any chance you can zip up a project and send to bu...@candlelightinteractive.com with scenes I can open up and see both a) the arm bending issue and b) the stuttering issue?
Reply all
Reply to author
Forward
0 new messages