c# - Unity2D collisions and some physics -


i'm making 2d tank shooter game, got problems , questions:

  1. i got problems collisions.

gif of problem here. go tank collision problem. (i can't post more 2 links because of low reputation, have go images manualy, sorry.)

i need make tank not shown above. i'm using rigidbody on empty parent , box collider on tank body.

my "tank (root)" in inspector , "tankbody" (hull) in inspector here.

tank movement code:

using unityengine; using system.collections;  public class movement : monobehaviour {     public float thrust;     public float rotatingspeed;     public rigidbody rb;  void start () {     rb = getcomponent<rigidbody>(); }  void update () {     if (input.getkey (keycode.w)) {         transform.translate (vector2.right * thrust);                }     if (input.getkey (keycode.s)) {         transform.translate (vector2.right * -thrust);     }     if(input.getkey(keycode.a)) {         transform.rotate(vector3.forward, rotatingspeed);     }     if(input.getkey(keycode.d)) {         transform.rotate(vector3.forward, -rotatingspeed);     }  } 

}

  1. my bullets fly in 0 gravity/space. need them not hover that(i got similar problem before , couldn't fixed it..). there gif in first link in 1.st problem. shooting code:

    using unityengine;

    using system.collections;

    public class shooting : monobehaviour {

        public rigidbody2d projectile;     public float speed = 20;     public transform barrelend;  void update () {     if (input.getbuttondown("fire1"))     {         rigidbody2d rocketinstance;         rocketinstance = instantiate(projectile, barrelend.position, barrelend.rotation) rigidbody2d;         rocketinstance.addforce(barrelend.right * speed);     } } 

    }

i managed fix both problems. fix problem number 1. used add force. new moving forwand , backward looks this:

if (input.getkey (moveforward)) {         //transform.translate (vector2.right * thrust); old !!           rb2d.addforce(transform.right * thrust * time.deltatime);     } if (input.getkey (movebackward)) {         //transform.translate (vector2.right * -thrust); old !!         rb2d.addforce(transform.right * -thrust * time.deltatime); 

and had adjust mass smaller (from 2000 1), thrust bigger (from 0.2 50000) , set drag 50, angular drag 100.

2nd problem got fixed setting drag , angular drag bigger value. that's it!


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -