# rigidbody2D unwanted collisons

Hi all!
I ve been trying the new 2D features of unity.Im just trying to make a quick demo of a platformer level.I added rigidbody2D to the player character added a box collider to it and use the following script to move the player horizontally.

``````#pragma strict
private var v:int;
private var h:int;
var force:float;
public var facingRight:boolean;
function Start () {
facingRight=true;
}

function Update () {
/*if(Input.GetButtonDown("Jump")) {
//anim.GetComponent(Transform);
Debug.Log(anim);
anim.SetBool("strike",true);
}
if(Input.GetButtonUp("Jump")) {
anim.SetBool("strike",false);
}*/
//if() {

//}
}
function FixedUpdate() {
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
//rigidbody2D.transform.position.x+=0.1 * h;
if(h > 0  !facingRight)
Flip();
else if(h < 0  facingRight)
Flip();

//rigidbody2D.transform.position.y=-0.5f* v;
}

function Flip ()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
var theScale:Vector3;
// Multiply the player's x local scale by -1.
theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
``````

the player moves fine but at places,the player stops as if he hit a wall and dont move further.but actually there is no physics component present there except a smooth ground where he walks.

FYI I kept the gravity scale to 9.8.

also I noticed that in the 2D tutorial given in unity(the potato guy one),the gravity is set to 1 and the game works fine.but if i set the gravity to 1 in my game the guy floats as if he’s in space.

this problem is buggin me for weeks.I tried all the methods i can possibly imagine but this is over my head.

Hi I recommend using this component GitHub - prime31/CharacterController2D

much thanks! it solved all of my problems regarding character control!

how to close this topic?

thanks that worked!! how to close this thread?