- Home /
Question by
Lautaro-Arino · Jan 16, 2014 at 09:09 PM ·
2drigidbody2dphysics2d
AddingForceAtPoint not doing anything
Im using Rigidbody2D for some game objects. It seems that when i AddForce or AddForceAtPoint i the game objects that i use it are mostly affected on the Y axis and hardly at all on the x axis. I dont understand why. To really get any effect on the x axis i need to have a very strong force like *10 000. But the effect on the y axis is then extremely strong and shoots the object out of screen. And even this just nudges the game object on the x scale.
Here is a script i use that triggers a AddForceAtPoint for all game objects close to the mousepointer and this gives this weird result i described above.
void ExplodeZombiesInArea ()
{
var blastRadius = 1.0f;
var impactPosition = Tools.GetMouse2DWorldPosition ();
print (impactPosition);
//Create sphere by mouse position and get all colliders inside it
Collider2D[] colliders = Physics2D.OverlapCircleAll (impactPosition, blastRadius);
Blip2D.BlipAtPosition (impactPosition, 0.2f, 1.0f, 0.5f);
foreach (var collider in colliders) {
if (collider != null && collider.name == "ZombieBoy") {
var zombie = collider.gameObject.GetComponent<ZombieBoyController> ();
if (zombie) {
zombie.AddForceAtPosition (impactPosition, 400f);
}
}
}
}
BlipAtPosition displays a circle in the game. I use this to make sure the force comes from the mouse pointers position.
Comment