- Home /
Chewing gum Physics Material 2D
I am trying to create a GameObject that should work like a chewing gum. For that I did the following:
Create an empty GameObject
Drag the sprite (same width and height) into the previous GameObject
Add a Box Collider 2D to the GameObject
Create a Physics Material 2D
Add the previous Physics Material 2D to the Box Collider 2D
I used a Bounciness value of 0.3f so it bounces a little and a Friction value of 0.8f so the objects that touch it get stuck but it is not working. I also tried with several combinations of those values but with no luck.
Is this the right approach? I am new to Unity so maybe I am not getting how really Physics Material work.
Please note that I am using 2D mode settings.
All of these things you can do without using an empty gameObject. you can apply all these setting to the sprite. (unless you mean texture and not sprite).
What is actually not working? Is it not bouncing? Is it not sticking?
The bounciness value works as I expect but the Friction value does not. When I put 0 the ball in contact slides faster but I want the opposite. So I tried with 0.8, 1, 10, 100 but the ball in contact does not get stucked. I think I will try to create a joint dynamically to get the ball stuck. What you think about that? :7
Answer by moneymaker · Mar 08, 2014 at 03:30 PM
I ended up using another approach that works better. Using OnCollisionEnter2D
I create a SpringJoint2D
connecting the object that touched it. I also change the linear drag of the same object so it does not move too much.
public class Gum : MonoBehaviour {
void OnCollisionEnter2D(Collision2D collider)
{
GameObject go = collider.gameObject;
SpringJoint2D joint = gameObject.AddComponent<SpringJoint2D>();
joint.connectedBody = go.rigidbody2D;
go.rigidbody2D.drag = 10;
}
}
Your answer
Follow this Question
Related Questions
How click and drag a 2D game object without click and dragging the Camera Orthographic? 1 Answer
Getting a chest is not enabling my collider 0 Answers
If i flip the scale from a sprite, how do i make my game object child flip aswell? 0 Answers
SpritesSheet 2D - Changing Color using RBG setting? 1 Answer
sprite after animation 1 Answer