Reputation: 21
Hi guys I want to ask how can I set a .addforce with different direction when my character hits the objects. My character is kicking left and right and i want the object to go to different direction with different force. And i want my character not hitting the object when it`s running.
Here is my character and I have 2 box collider for the feet and for the trigger
Here is my code for the force.
Public void Sipa()
{
if (canSipa == true)
{
_pitcha.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000, 5000));
//_pitcha.GetComponent<Rigidbody2D>().AddForce(transform.right * kickForce);
}
}
Upvotes: 0
Views: 91
Reputation: 281
First of all, Public doesn't exist, try public
instead. Unity has functions that you can override, in this case try using the following:
void OnCollisionEnter2D(Collision2D col) {
if(col.gameObject.tag == "Tag of object that is expected to collide") {
_pitcha.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000, 5000));
}
}
Upvotes: -1