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 /
  • Help Room /
avatar image
0
Question by gran4de · Apr 08, 2017 at 11:42 PM · dragfrictiondash

Dashing cube ability problem

Hello, I've got a problem with creating a dash ability in my game (3d)

I've currently got it so that when you double press D, I add velocity in that direction. Here comes the problem, I've given the player a material that has 0 friction. Otherwise you would be able to jump in walls and kinda get stuck in them. Now you just glide down when jumping against a wall.

Now, when I add velocity, It just keeps going, and doesn't stop. Because there is nothing to stop the velocity since there is no friction. I've given the player's rigidbody drag, so that there is some form of friction. but its still not working as I would like.

I've tried to add more drag while dashing, but if I give the player more drag, it falls down more slowly too, which I don't want.

This is my current code:

 public float xSpeed = 1;
 public float zSpeed = 1;
 public bool Grounded = false;

 public bool reset;
 public bool firstButtonPressed;
 public float timeOfFirstButton;
 public float DashRightSpeed = 10;
 public float HoldSpeedRight;

 public float dashTimer = 3f;
 public float dragger = 1;
 public Rigidbody rb; 
 Vector3 CurrentVelocity;

 // Use this for initialization
 void Start () {
     rb = GetComponent<Rigidbody> ();
     //rb.drag = 20;
 }

 void OnCollisionEnter(Collision col){
     if (col.gameObject.tag == "ground") {
         Grounded = true;
     }
 }

 // Update is called once per frame
 void Update () {
     CurrentVelocity = rb.velocity;

 

     //Activate Dash
     if(Input.GetKeyDown(KeyCode.D) && firstButtonPressed) {
         //firstButtonPressed = false;

         if(Time.time - timeOfFirstButton < 0.5f && dashTimer >= 3) {
             firstButtonPressed = false;
             dashTimer = 0;
             Debug.Log("DoubleClicked");

             dragger = 3;
             rb.velocity = new Vector3(10, CurrentVelocity.y, CurrentVelocity.z);

         }
     } 

     //First button press
     else if(Input.GetKeyDown(KeyCode.D) && !firstButtonPressed) {
         firstButtonPressed = true;
         timeOfFirstButton = Time.time;
     }
         
     // Second button press too slow, reset First press bool
     if (firstButtonPressed) {
         if (Time.time - timeOfFirstButton > 0.5f) {
             firstButtonPressed = false;
         }
     }



     rb.drag = dragger;

     if (dragger > 1) {
         dragger = dragger - Time.deltaTime * 4;
     }




     // Reset timer for dash
     if (dashTimer < 3) {
         dashTimer += Time.deltaTime;

     }



     
     Holder.xPos = transform.position.x.ToString();
     Holder.zPos = transform.position.z.ToString ();

 }

 void FixedUpdate(){
     float x = Input.GetAxis ("Horizontal") * xSpeed;
     float z = Input.GetAxis ("Vertical") * zSpeed;

     transform.Translate (x, 0, z);


     if (Input.GetKey(KeyCode.Space) && Grounded) {
         Grounded = false;
         rb.velocity = new Vector3(CurrentVelocity.x, 10, CurrentVelocity.z);
     }
 }


I'm sorry for the spaghetti code, If anyone knows how i could get this to work, I would be really grateful.

Example of dashing: Here

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 gran4de · Apr 11, 2017 at 03:57 PM

bumb bumb bumb bumb

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

97 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

Related Questions

Move rigidbody cube without it tumbling 2 Answers

Cant figure out simple camera orbit 0 Answers

how to create dress up scene in unity? 0 Answers

how to drag a instantiate Panel (prefab)? 0 Answers

Compensate slow fall when using rigidbody.drag 0 Answers


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