Add Force isnt working
void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "atack")
{
// the boss dont get this force \/, why?
bodyRigid.AddForce(transform.up * 150);
bossHealth = bossHealth - 1;
PlaySound(0); // damage sound
animator.SetTrigger("attack");
if (bossHealth == 0)
{
Rigidbody2D cloneBlood = Instantiate(blood, spawnBlood.position, Quaternion.identity) as Rigidbody2D;
cloneBlood.AddForce(spawnBlood.up * 150);
// cloneBlood gets the force normally.
StartCoroutine(timeDeath());
}
}
}
Why the bodyRigid doesnt apply the force in the boss?
Have you tried -transform.up or transform.right? maybe your force is in a weird direction.
@vintar I've already done that. the weird thing is this is the only line that doesnt work. The script is attached to the boss.
by the way It doesnt give me any error
Answer by brenolimaa96 · May 25, 2016 at 08:51 PM
I've made it, searched more in http://answers.unity3d.com/questions/982202/addforce-transformright-not-working-correctly-in-2.html
So I've used
bodyRigid.AddForce(Vector2.up * 150, ForceMode2D.Impulse);
Really dont know what is this ForceMode, but it's working now.
Probably it was adding 3D force and getting confused. If that is the case, Unity should probably make AddForce2D method.
Your answer
Follow this Question
Related Questions
Move gameObject on UI Button Press 2 Answers
UI GameObject (Button prefab) randomly changing Z axis RectTransform when instantiated 1 Answer
How can i assign a GameObject to another but only have some of its components? 1 Answer
GameObject not looking at me.. 1 Answer
Enemy Attacking Even When Not In Range 2 Answers