Code for a crappy ragdoll zombie

Hey guys,

I’m surprised with how much i’ve been struggling with this. I have a zombie ragdoll with a nav mesh agent attached to the pelvis, which works fine (looks like shit though). I additionally want the arms to independently reach out for the player that the nav agent is targetting. My issue is, i’ve tried using addforce to rigid body, translate and vector’s moveTowards. However, either the ragdoll glitches/breaks or nothing appears to happen. If anyone has any ideas on how to fix this I’d be grateful.

Here’s the last thing i tried to do.

public class ForceTowardTarget : MonoBehaviour {

    private float targetDistance = 5;
    private float force = 10000;
    public Transform target;

	// Update is called once per frame
	void Update () {
        target = GetComponentInParent<Target_AI>().target;

        if (target != null)// && Vector3.Distance(target.position, this.transform.position) < targetDistance)
        {
            Vector3.MoveTowards(this.transform.position, transform.position, force);
        }
	}
}

Thanks, Bazzalisk.

Your

             Vector3.MoveTowards(this.transform.position, transform.position, force);

Needs to be

transform.position = Vector3.MoveTowards(this.transform.position, transform.position, force * Time.deltaTime);

Because Vector3 references are only helper variables, it doesn’t actually pass a movement off to the gameObject. Same as Vector3.Right will never do anything on its own, unless applied to another Vector3.