- Home /
Player gets stuck on collision when jumping up a platform.
My character gets stuck if trying to jump up on a platform while running towards it. It has a box collider and a sphere collider. Like this: http://i.imgur.com/ov5bHdw.png
Any suggestions on how to fix this?
Are you using Unitys native 2d-tools? What does your characterController script look like?
Answer by algizmo · May 13, 2014 at 11:52 PM
This is a bit late :), but I had the same issue.
Just after the line that reads horizontal axis
float move = Input.GetAxis ("Horizontal");
added the following line
if (!grounded && Mathf.Abs(move) > 0.01f) return;
So, if the player is not grounded and he is moving then just return and do not execute any movement code. Again, I assume your are using tutorial script. So, the whole FixedUpdate looks like this
void FixedUpdate ()
{
grounded = Physics2D.OverlapCircle (groundCheck.position, groundedRadius, whatIsGround);
anim.SetBool ("Ground", grounded);
anim.SetFloat ("VerticalSpeed", rigidbody2D.velocity.y);
float move = Input.GetAxis ("Horizontal");
//prevents the player from getting stuck into platform
if (!grounded && Mathf.Abs(move) > 0.01f) return;
anim.SetFloat ("Speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 && !isFacingRight)
Flip ();
else if (move < 0 && isFacingRight)
Flip ();
}
Answer by acastro · Feb 06, 2014 at 08:14 PM
If you are using the tutorial script, just add this 'if' before this line:
if (grounded)
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
Well, I am investigating that issue but this is surely not fixing anything.
Answer by Max_power1965 · Dec 15, 2015 at 09:54 PM
There is new unity component called platform Effector 2D that will allow you to do that: more info here: http://docs.unity3d.com/Manual/class-PlatformEffector2D.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613125416im_/https://answers.unity.com/themes/thub/images/avi.jpg)