# rigidbody2D unwanted collisons

Discussion in '2D' started by Jakkarrl Games, Dec 31, 2013.

1. ### Jakkarrl Games

Joined:
Sep 2, 2013
Posts:
4
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.

Code (csharp):
1.
2. #pragma strict
3. private var v:int;
4. private var h:int;
5. var force:float;
6. public var facingRight:boolean;
7. function Start () {
8. facingRight=true;
9. }
10.
11. function Update () {
12.  /*if(Input.GetButtonDown("Jump")) {
13.             //anim.GetComponent(Transform);
14.             Debug.Log(anim);
15.             anim.SetBool("strike",true);
16.             }
17.     if(Input.GetButtonUp("Jump")) {
18.             anim.SetBool("strike",false);
19.             }*/
21.             //if() {
22.
23.             //}
24. }
25. function FixedUpdate() {
26.             h = Input.GetAxis("Horizontal");
27.             v = Input.GetAxis("Vertical");
28.             //rigidbody2D.transform.position.x+=0.1 * h;
31.         if(h > 0  !facingRight)
32.             Flip();
33.         else if(h < 0  facingRight)
34.             Flip();
35.
36.
37.             //rigidbody2D.transform.position.y=-0.5f* v;
38. }
39.
40. function Flip ()
41.     {
42.         // Switch the way the player is labelled as facing.
43.         facingRight = !facingRight;
44.         var theScale:Vector3;
45.         // Multiply the player's x local scale by -1.
46.         theScale = transform.localScale;
47.         theScale.x *= -1;
48.         transform.localScale = theScale;
49.     }
50.
51.
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.

Last edited: Jan 1, 2014

Joined:
Dec 31, 2013
Posts:
1
3. ### Jakkarrl Games

Joined:
Sep 2, 2013
Posts:
4
much thanks! it solved all of my problems regarding character control!

how to close this topic?

4. ### Jakkarrl Games

Joined:
Sep 2, 2013
Posts:
4
thanks that worked!! how to close this thread?