Search Unity

Movement trick

Discussion in '2D' started by yassir5, Oct 14, 2018.

  1. yassir5

    yassir5

    Joined:
    May 28, 2018
    Posts:
    2
    Hello All,

    I would really appreciate it if someone could point me to the right direction of making this kind of attack where when my character shoots hes pushed back, just like the brominator in Broforce :


    I would really appreciate your help!!

    Thank you
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    If the character has physics, then you could add forces to the rigidbody with each shot, slowly pushing him backwards from the way his gun is facing. If the character is not physics based, you could fake it by just moving it backwards with transform position, and make him animate to jitter up and down a bit.
     
  3. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Just add a force or vector opposite of the way the character is facing. Here is code:

    Code (CSharp):
    1. int KnockBackForce = 10;
    2. rb.GetComponent<Rigidbody2D>();
    3. rb.AddForce(transform.right * KnockBackForce * -1);