I cant addForce to rigidbody.

Dear Unity users,

Here is my code:

public bool bePushed;
Rigidbody rb;

void start(){
rb= GetComponent();
}

void Update(){
if (bePushed)
{
rb.AddForce(-transform.forward * 100);
bePushed= false;
}
}

So there is a giant enemy on my game. This code is at my Player. When Giant Enemy hits, bePushed is becoming true. I checked that part is working. And in if, bePushed=false is working to. But my character is not moving. How can i fix that? Please help me.

Sincerely,
Kardok.

Hi,
you have some syntax errors:
It is bool not Bool, Start() not start
rb = GetComponent(); not with ==

After that, use AddForce into FixedUpdate() not Update.
And i think the player wont stop when bePushed = false… When you add a force, its continuous. If you want the player stops you have to slowdown/stop its velocity…

1 Like

I fixed those part like u said. And added:

void FixedUpdate()
{
if (bePushed)
{
rb.AddForce(-transform.forward* 100);
bePushed=false;
}
}
But it didnt work. Could it be because of something on rigidbody?

Okay my rigidbody has isKinematic. So i will close it, push it and turn it on again. İt will probably work.