Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
1
Question by farhanfaishal · Nov 11, 2019 at 03:01 PM · 2d2d game2d-platformerrigidbody2d2d-physics

,Hey! I'm trying to make a Dash move like Celeste but my Dash doesn't seem to work Horizontally(X Axis), My Dash is working perfectly fine Upward and Downwards(Y Axis).

Hey! I'm trying to make a Dash move like Celeste but my Dash doesn't seem to work Horizontally(X Axis), My Dash is working perfectly fine Upward and Downwards(Y Axis). Everything else in my code is working perfectly fine. Below is the my code and any help will be appreciated. Thank you!

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Move2 : MonoBehaviour {

 [SerializeField] public LayerMask whatIsGround; 
 [Header("Stats")]
 float x = 0f;
 float y = 0f;
 float xRaw = 0f;
 float yRaw = 0f;
 public float runSpeed = 10f;
 Vector2 dir;
 public float jumpForce = 10f;
 public float dashSpeed = 10f;
 public Transform feetPos;
 public float checkRadius;


 [Space]
 [Header("Booleans")]
 public bool canjump = false;
 private bool isGrounded;
 public bool canDash = false;


 [HideInInspector]
 public Rigidbody2D rb;


 void Start ()
 {
     rb = GetComponent<Rigidbody2D>();
 }

 void Update()
 {
     isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);

     x = Input.GetAxis("Horizontal");
     y = Input.GetAxis("Vertical");
     xRaw = Input.GetAxisRaw("Horizontal");
     yRaw = Input.GetAxisRaw("Vertical");
     dir = new Vector2(x, y);     
     

     if(Input.GetButtonDown("Jump") && isGrounded == true)
     {
         canjump = true;
     }

     if(Input.GetButtonDown("Fire1"))
     {
         canDash = true;
     }


     if(dir.x > 0)
     {
         transform.eulerAngles = new Vector3(0, 0, 0);
     }

     if(dir.x < 0)
     {
         transform.eulerAngles = new Vector3(0, 180, 0);
     }
 }

 void FixedUpdate()
 {
     Walk(dir);

     if(canjump == true)
     {
         Jump(Vector2.up);
     }

     if(canDash == true)
     {
         if(xRaw != 0 || yRaw != 0)
         {
             Dash(xRaw, yRaw);
         }    
     }

     
 }

 void Walk(Vector2 dir)
 {
     rb.velocity = new Vector2(dir.x * runSpeed, rb.velocity.y);
 }

 private void Jump(Vector2 dir)
 {
     rb.velocity = new Vector2(rb.velocity.x, 0);
     rb.velocity += dir * jumpForce;
     canjump = false;
 }

 void Dash(float x, float y)
 {

     rb.velocity = Vector2.zero;
     Vector2 dir = new Vector2(x, y);

     rb.velocity += dir.normalized * dashSpeed;
     canDash = false;
 }

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Menzle · Apr 04, 2021 at 03:21 PM

Hi, sorry that i can't really help you, I kinda have the same problem, just checking if you found the solution yet.

Comment
Add comment · Share
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

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

251 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 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

Softbody physics with 2D sprites 1 Answer

Jumping from special jump orb 1 Answer

Problem with Falling Platform Script 3 Answers

2D Jump using "Rigidbody2D.AddForce" doesn't work. 1 Answer

Problem with 2D movement. My character is moving by himself between two points... :) 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