3d code into 2d

hi…can anyone plz tell me how to convert this line in to use for 2d rigidbody?this script is provided by someone in tutorial in youtube…
need help with converting below to 2d…i am learning…would really appreciate…thanks.

ballRigidBody.AddForce(300*Input.GetAxis (“Horizontal”),450f,0);

and

foreach (ContactPoint Contact in col.contacts)
{
if ( Contact.thisCollider==collider)
{
float english = Contact.point.x - transform.position.x;
Contact.otherCollider.rigidbody.AddForce(300f*english,0,0);
}
}

It looks from your code like this is never doing anything on the Z axis, so TECHNICALLY there is NOTHING you need to do to make it 2D :slight_smile: Just keep the Physics Engine as 3D and since you never touch the Z axis, it’s kind of irrelevant (though I’m sure someone can point out how I’m wrong on that one… aaaaanyway…)

That doesn’t really answer your question :slight_smile:

Everything looks good, just change over to use the 2D versions of the components referenced. For example, if the component on your GameObject is “Rigidbody2D” calling Contact.otherCollider.rigidbody isn’t going to get your rigidbody. You need to change any references to the 2D versions (Rigidbody, Collision, Collider, etc)

I’m not gonna rewrite your code though :wink: Just remember, if your physics setting is set to 2D, you need to use 2D components, and reference those components by their 2D names in scripts!

Hope that Helps!

Adam