How to get force from a rigidbody2D?

As the title explains, I need to know how to get the force from an rigid body object, I have already applied the force and the object moves through the applied force. I need to apply the force received from the rigid body to a different game object script. Thanks.

EDIT 01: I have uploaded the image for better clarity. 41770-ipad.png

From the comments, it sounds like you are trying to make your projectile follow a fixed Bezier curve. You probably don’t need to do this, unless you are going for some kind of cartoon or non-realistic physics.

For an Angry Birds style projectile, just apply the force in the direction the player aimed, and let gravity do the work. The arc will happen naturally, and the projectile will hit the target with whatever force you would get in the real world, based on the initial acceleration, the gravity setting, and masses of the two objects.

If you want to adjust the behavior to get non-realistic physics, then what you can do is store the acceleration data in a variable, and then implement an OnCollisionEnter handler:

This will give you a Collision object. You can take its .rigidBody and apply whatever extra forces you want to it:

I think you might be over complicating, if you think that in Angry birds, the bird moves by following a path. But that path is there just so the user knows where he’s shooting. What’s happens there is that game records the what vector user has dragged, and then applies force inverse of that vector. The bird then shoots, and as gravity loves to pull everyone down, it goes in a curve, instead of flying of screen in that vector direction. When it hits another rigid body the physics engine takes care of the calculations. It would just be too tedious to do all the physics calculations yourself.

Now from my understanding of the behaviour you are trying to achieve is; longer the user pulls, more accurately the force will be applied on the fruit (please tell me if I’m wrong). So what you want to do is set the delta percentage amount the force is allowed to stray using 1 / Vector component i.e. you have to do it for all x, y, and z separately, let’s say deltaX for x component. Then you have to use Random.Range; where min is x - x * deltaX, and max is x + x *deltaX, to set the components of the force which will be applied. This should make it so that more the user pulls, more accurate the force vector will be. Remember as the value approaches zero, the deal variable is going to approach infinity. So you should make sure it never does.

If your issue is with different sizes, then you can change the mass property of each rigid body in the prefab. So for larger fruits will require more force to move the same distance.

If something is unclear, don’t be afraid to ask. :slight_smile:

PS: Just to clarify only objects like missiles are constantly applying force, you easily can get the force of these object, which would be mass X ∆velocity per second. But objects like thrown ball, the force is only applied just once (impulse), and they would maintain the same velocity if there is no friction. Have a look at Force Modes in Unity.

I would do this:

  • throw the fruit
  • make the collider a trigger so the fruit won’t loose velocity and save it on enter
  • with the magnitude of the velocity you can do your math determining whatever it shall do on the spline (didn’t get it actually)
  • while moving along the spline, adjust the velocity vector in FixedUpdate without changing anything else on the rigidbody. If you want to be perfectly accurate you will need to Lerp between spline points because you won’t reach each one due to time stepping.
  • after the spline part is done just stop influencing the velocity and it’ll move physically correct again

Hope that’s an idea