Why does my code not push my game object?

So basically, my game object is a zombie head which is childed to a prefab named zombie. I want to knock the zombie’s head over when the zombie dies, but it doesn’t happen. Here is my code and the zombie head’s components and their respective settings:


Also, just so that you know, I am correctly fetching the rigid body component from the head since I can interact with the settings of the component.
What be da problem in my code?

You can try using “this.transform.Translate(Vector3);” to move the zombie head. Cause the head is spinning right? it’s just not being pushed off the body.

The head isn’t spinning. Nothing happens to the head. Also, I want more of a push than a movement because I want the head to topple over.

I’m thinking the zombie is getting destroyed before it has a chance to do the deathphysics, try commenting out the destroy code first to see if thats the case.

Edit: Also in the picture the zombie head has a Dodeathphysics script attached to it, but the code you are showing us is the movement script? That may also be the cause. Using the wrong script?

The zombie getting destroyed before it has the chance to topple over is not a problem since it gets destroyed 4 seconds later and I did what you suggested of commenting it out and that too did not work.

Also the DoDeathPhysics script does nothing right now. I thought of creating a separate script and moving the death physics there so that the enemy movement script does one thing.

I made a GIF showing the code in action so that you can see what happens to the zombie and its head: https://gyazo.com/fef5915264505cac64671a15f8e524c6

Right it’s just that the headphysics is inside of the enemy movement script but the zombiehead doesnt have that script attached to it so that may be why it’s not doing anything.

After messing around with Unity, I finally found out the problem. The zombie prefab had a box collider as well meaning that the zombie head could not move since it was inside a box collider.

Thanks for your time though.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms