Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ncp12 · Nov 28, 2021 at 06:08 AM · unity 2ddash

Dash for 2d game

hi im trying to make a game and am currently struggling with the dash mechanic, and really need help.

thanks in advance!

here is my code so far:

 private Rigidbody2D rb;
 public float speed;
 public float jumpForce;
 private float moveInput;

 private bool isGrounded;
 public Transform feetPos;
 public float checkRadius;
 public LayerMask whatIsGround;

 private float jumpTimeCounter;
 public float jumpTime;
 private bool isJumping;
 public float dashSpeed = 100f;
 private float dashTime;
 public float startDashTime;
 private int direction;



 // private Vector2 lastMoveDir;


 void Start(){
     rb = GetComponent<Rigidbody2D>();
     dashTime = startDashTime;
 }
 
 void FixedUpdate(){
     moveInput = Input.GetAxisRaw("Horizontal");
     rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
     // float x = Input.GetAxis("Horizontal");
     // float y = Input.GetAxis("Vertical");
     
     // Vector2 dir = new Vector2(x, y);
 }

 void Update(){
     
     float xRaw = Input.GetAxis("Horizontal");
     float yRaw = Input.GetAxis("Vertical");
     isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);

         if(isGrounded == true && Input.GetKeyDown(KeyCode.W)){
             isJumping = true;
             jumpTimeCounter = jumpTime;
             rb.velocity = Vector2.up * jumpForce;
         }

         if(Input.GetKey(KeyCode.W) && isJumping == true){

             if(jumpTimeCounter > 0){
                 rb.velocity = Vector2.up * jumpForce;
                 jumpTimeCounter -= Time.deltaTime;

             }else{
                 isJumping = false;
             }
             
         }

         if(Input.GetKeyUp(KeyCode.W)){
             isJumping = false;
         }
     if(Input.GetKeyDown(KeyCode.Space)){
         if (direction == 0){
             if (Input.GetKeyDown(KeyCode.A)){
                 direction = 1;
                 Debug.Log("left");
             }else if (Input.GetKeyDown(KeyCode.D)){
                 direction = 2;
                 Debug.Log("right");
             }
         }else{
             if (dashTime <= 0){
                 direction = 0;
                 dashTime = startDashTime;
                 rb.velocity = Vector2.zero;
             }else{
                 dashTime -= Time.deltaTime;

                 if(direction == 1){
                     rb.velocity = Vector2.left * dashSpeed;
                 } else if(direction == 2){
                     rb.velocity = Vector2.right * dashSpeed;
                 }
             }

         }

     }
     
 }
 


}

my movement is fine, but the dash...smh it just wont work. btw, I'm going for a celeste feel to this movement. thanks!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MilitaryG · Nov 28, 2021 at 06:11 AM 0
Share

What do you expect to happen?

What must it do?

avatar image ncp12 MilitaryG · Nov 28, 2021 at 06:52 AM 0
Share

well i was looking for like a short burst of speed, sorta like a small teleport to whichever direction I went in last

avatar image ncp12 ncp12 · Nov 28, 2021 at 06:52 AM 0
Share

hollow knight, celeste, all good examples..and great games :)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

178 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity2d .velocity dash speed 2 Answers

why chartboost sdk is not integrating to unity? 0 Answers

Unity Build Error Duplicate class,Unity Build Error duplicate class 2 Answers

covert liste of vector3 to Json 1 Answer

Cinemachine Confiner without IsTrigger? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges