- Home /
 
 
               Question by 
               parker61202 · Jan 03 at 03:10 AM · 
                2dtopdownattackdash  
              
 
              2D Dash attack
Hello, I am making a rogue like in similar style to Nuclear Throne. I am fairly new to programming and can't find any answers that fit my scenario so I figured I would ask here.
I would like to add a melee to the game where upon the push of a button (mouse 2 at current moment) the character would be propelled forward a bit in the direction of the mouse and have an active hit box. Sort of like a lunge attack.
I currently cannot figure out a way to do that. Please Help.
Here is my code currently:
Player movement:
      Rigidbody2D RB;
  
      float horizontal;
      float vertical;
      float moveLimiter = 0.7f;
  
      public float runSpeed = 8f;
      public float offset;
  
      void FixedUpdate()
      {
          if (horizontal != 0 && vertical != 0) // Check for diagonal movement
          {
              // limit movement speed diagonally, so you move at 70% speed
              horizontal *= moveLimiter;
              vertical *= moveLimiter;
          }
  
          RB.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
      }
  
 
               Mouse Tracking:
        public CameraController Cam;
        public Transform shoulder;
  
        Cam = CameraController.instance;
         //weapon rotation and movement
         Vector3 shoulderToMouseDir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - shoulder.position;
         shoulderToMouseDir.z = 0; // zero z axis since we are using 2d
         transform.position = shoulder.position + (armLength * shoulderToMouseDir.normalized);
         Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
         Vector3 dir = Input.mousePosition - pos;
         float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
 
              
               Comment
              
 
               
              Your answer