Object sticks to the side of the collider
Greetings, I'm making a 2D platformer. I'm using 3D physics in it (100% 3D physics, no mix). The problem is that when the player jumps from a ground to another, occasionally the character hits the side of the platform. In these cases the character gets sticked to the side (until I let the move button go). Either way this makes the gameplay unbearable. How to solve this? I'm using this as reference where the tutor faces this issue as well by the way. My platforms are 3D boxes, my character is a 3D capsule. Everything else I used like in the tutorial I posted. I would perefer the player to slide up to the box if that's possible, if not, killing the character is fine as well. All the help appreciated.
Some code: my character movement:
void Start ()
{
//in dev: setting the pos so I don't have to play it over again.
gameObject.transform.position = new Vector3(47.1f, -4.18f);
//
jump = true;
moveForce = 36.50f;
maxSpeed = 8.0f;
jumpForce = 1000.0f;
grounded = false;
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
grounded = Physics.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
if(Input.GetButton("Jump") && grounded)
{
jump = true;
}
}
void FixedUpdate()
{
//constant movement forward. needs to be updated because of the fall.
Moving();
}
void Moving()
{
float h = Input.GetAxis("Horizontal");
rb.velocity = new Vector3(maxSpeed * h, rb.velocity.y);
//if(h * rb.velocity.x < maxSpeed)
//{
// rb.AddForce(Vector3.right * h * moveForce);
//}
//if (Mathf.Abs(rb.velocity.x) > maxSpeed)
//{
// rb.velocity = new Vector3(rb.velocity.x * maxSpeed, rb.velocity.y);
//}
if (jump)
{
//anim.SetTrigger("Jump");
rb.AddForce(new Vector3(0.0f, jumpForce));
jump = false;
}
}
Answer by LightningStorm102 · Mar 17, 2019 at 08:49 PM
Hello!
The answer is found in this video: youtube.com/watch?v=QGDeafTx5ug∈dex=2&list=PLBIb_auVtBwBotxgdQXn2smO0Fvqqea4-&t=0s
If you don't want to watch it, here is the answer in a nutshell: Make a new physics material. Then set it's friction to 0. Now select your player and drag this material into the material slot of the Rigidbody component.
This should fix your problem. :)
Hey I'm having a similar issue in 2d where when my player touches my enemy he gets stuck and I can't walk away or anything! I have seen lots of people give your solution to the problem, but when I used it I still had the problem and worse my characters, just slide around the map.. the other solution I have seen is to make boxes out of edge colliders, idk if that works cause when I tried it my characters stopped colliding with the ground.. DO you know any other fixes?
I adjusted Physics 2D and to set the Velocity Threshold as low as I could go and physics2d and increase the default contact offset. Both had no effect, A fix I found was to add bounciness to the material, and I think lowering friction helped a bit, but bounciness of about .36 fixed my issue.