Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 EDUX77 · Sep 09, 2014 at 02:52 AM · javascriptmovementfirst-person-controllerdashrelative position

FPShooter sideway/forward dash?

I'm in quite a pickle right now. My goal with this script is to make a sideways (right/left) and forward individual dashes. It contains multiple problems and I consider myself a complete noob when it comes to scripting. If someone has an alternative or solution of some sort I would be eternally grateful. The problems with this script are quite a few: (-)First when I rotate the camera the dashes don't move relatively to it, that dash's movement are always with relation the the X/Z world axis (-)Second, when i try to make the forward dash (Q and E keys simultaneously) it registers the 3 different dashes, left, right and forward. (-)Lastly my character is obviously affected by gravity, is there a way to disable it while I'm dashing.

 //private var isDashing = false; was originally going to, but not using
 var strength : int = 20;
 var dashCost = 25;
 private var canDash = true;
 
 
 function Update () 
 {    
     if(Master.StaminaPoints < 25 )
         {
             canDash = false;
         }
     else
         {
             canDash = true;
         }
     
     if(Input.GetKeyDown("e") && canDash == true)
         {
             Debug.Log("Dash Right");
             gameObject.GetComponent(CharacterMotor).SetVelocity(Vector3.right * strength);
             audio.Play();
             Master.StaminaPoints = Master.StaminaPoints - dashCost;
         }
     
     if(Input.GetKeyDown("q") && canDash == true)
         {
             Debug.Log("Dash Left");
             gameObject.GetComponent(CharacterMotor).SetVelocity(Vector3.left * strength);
             audio.Play();
             Master.StaminaPoints = Master.StaminaPoints - dashCost;
         }
     
     if(Input.GetKeyDown("q") && Input.GetKeyDown("e") && canDash == true)
         {
             Debug.Log("Dash Forward");
             gameObject.GetComponent(CharacterMotor).SetVelocity(Vector3.forward * strength);
             audio.Play();
             Master.StaminaPoints = Master.StaminaPoints - dashCost;
         }
 }

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
1
Best Answer

Answer by Cherno · Sep 09, 2014 at 04:15 AM

  1. Try using transform.right etc. instead of Vector3.right. If that doesn't help, look into the Character Motor script and see how movement is accomplished there.

  2. Try calling the dashes with Input.GetKeyUp. Use GetKey to check if both Q and E are held down, and if yes, set a boolean "forwardDash" to true, and call the forward dash function. For the GetKeyUp check, add an if statement to check if "forwardDash" is set to false. If yes, then call either left or right dashing. If not, then only set dashing to false.

  3. The CharacterMotor script has variables for Gravity and MaxFallSpeed.

Comment
Add comment · Show 2 · 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
avatar image EDUX77 · Sep 10, 2014 at 11:30 PM 0
Share

Wow thank you Cherno!! I got the code to work. It's not perfect, I kind of got confused with your explanation about the forward dash but I think I did more less what you told me to. Anyway it works and I appreciate your answer. I'm gonna leave the code here just in case anyone ever comes across and needs it. private var isDashing = false; private var strength : int = 20; //var air = 10; //var ground = 30; var dashCost = 250; var forwardDash : boolean = false; private var canDash = true; private var dashLenght = .2;

 function Start ()
 {
     isDashing = false;
     Character$$anonymous$$otor$$anonymous$$ovement.gravity = 20;
 }
 
 function Update () 
 {    
     if($$anonymous$$aster.Sta$$anonymous$$aPoints < 250 )
         {
             canDash = false;
         }
     else
         {
             canDash = true;
         }
     
     if(Character$$anonymous$$otor.grounded == true)
         {
             //Debug.Log ("ground");
             strength = 30;
         }
     else
         {
             //Debug.Log ("air");
             strength = 20;
         }
     
     
     if(Input.Get$$anonymous$$eyUp("e") && canDash == true && isDashing == false && forwardDash == false)
         {
             Right ();
         }
     
     if(Input.Get$$anonymous$$eyUp("q") && canDash == true && isDashing == false && forwardDash == false)
         {
             Left ();
         }
     
     if(Input.Get$$anonymous$$ey("q") && Input.Get$$anonymous$$ey("e") && canDash == true && isDashing == false)
         {
             Debug.Log ("Down");
             forwardDash = true;
             Forward ();
         }
 }
 
 function Right ()
     {
         isDashing = true;
         Debug.Log("Dash Right");
         Character$$anonymous$$otor$$anonymous$$ovement.gravity = 0;
         gameObject.GetComponent(Character$$anonymous$$otor).SetVelocity(transform.right * strength);
         audio.Play();
         $$anonymous$$aster.Sta$$anonymous$$aPoints = $$anonymous$$aster.Sta$$anonymous$$aPoints - dashCost;
         yield WaitForSeconds(dashLenght);
         Character$$anonymous$$otor$$anonymous$$ovement.gravity = 20;
         isDashing = false;
     }
     
 function Left ()
     {
         isDashing = true;
         Debug.Log("Dash Left");
         Character$$anonymous$$otor$$anonymous$$ovement.gravity = 0;
         gameObject.GetComponent(Character$$anonymous$$otor).SetVelocity(-transform.right * strength);
         audio.Play();
         $$anonymous$$aster.Sta$$anonymous$$aPoints = $$anonymous$$aster.Sta$$anonymous$$aPoints - dashCost;
         yield WaitForSeconds(dashLenght);
         Character$$anonymous$$otor$$anonymous$$ovement.gravity = 20;
         isDashing = false;
     }
     
 function Forward ()
     {
         Debug.Log ("Forward");
         //if(Input.Get$$anonymous$$eyUp("q") && Input.Get$$anonymous$$eyUp("e"))
             //{
                 isDashing = true;
                 Debug.Log("Dash Forward");
                 Character$$anonymous$$otor$$anonymous$$ovement.gravity = 0;
                 gameObject.GetComponent(Character$$anonymous$$otor).SetVelocity(transform.forward * strength);
                 audio.Play();
                 $$anonymous$$aster.Sta$$anonymous$$aPoints = $$anonymous$$aster.Sta$$anonymous$$aPoints - dashCost;
                 yield WaitForSeconds(dashLenght);
                 Character$$anonymous$$otor$$anonymous$$ovement.gravity = 20;
                 isDashing = false;
             //}
         forwardDash = false;
     }
avatar image Cherno · Sep 10, 2014 at 11:48 PM 0
Share

Nice to know you got it to work. It always helps to just think about how something has to work, and map it out on good old notebook paper.

Pleaase flag the answer as accepted it it was indeed helpful :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

forward movement in camera direction (not direction of rigid body only) 3 Answers

Boost pad for character controller 0 Answers

Can't detect collision. 1 Answer

How do i on the y axis my camera from moving? 0 Answers

How to check for rapid key presses? 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