I’ve looked at a bunch of other posts with a similar problem, but their solutions aren’t working.
I have a prefab and added a box collider and rigidbody to it. I’ve also added a script to it. In the script I have
function FixedUpdate()
{
if(followPlayer)
{
print(Time.time + " " + pushDir);
transform.rigidbody.AddForce(pushDir * walkSpeed);
}
}
pushDir prints out and walkSpeed is 4. But my prefab doesn’t move. What am I missing?
Chances are ‘walkSpeed’ isn’t nearly high enough to create a significant force on the box. Remember that you need to overcome surface friction, as well as drag. In my experience, when I’m having problems with ‘AddForce’ not acting as expected, I increase the force to 10000 or something and see what happens. If it flies off into the distance, you’re good- just reduce it to something reasonable and you’re in business. Otherwise, there’s something else going on- either something is forcing the rigidbody not to move, or it is kinematic (and can’t).