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
0
Question by shane.rachel · Nov 02, 2012 at 08:00 AM · jumpdashdouble jumpbackward

dash left and right

okay, so I have compiled a script to make a character dash, both midair and on ground, but the character can only dash forward. I would like for the character to be able to dash both forward and backward.

Forward if I simply press the dash button (which I've assigned to the x key)

Backward if I press dash while holding down the left arrow key. This is part of what I came up with (only the pertinent stuff though)

var speed = 6;

var jumpSpeed = 8;

var jumpCount = 0;

var maxJump = 2;

var dashSpeed = 100.0;

var dashCount = 0;

var maxDash = 1;

private var moveDirection = Vector3.zero;

private var grounded : boolean = false;

function update () {

//allow free range horizontal movement while in air

if (!grounded) {

moveDirection.x = Input.GetAxis("Horizontal")*speed;

//air dash one time only

if (dashCount < maxDash) {

if (Input.GetKey (KeyCode.X)) {

moveDirection.x = dashSpeed;

dashCount++;} } }

else {moveDirection = Vector3(Input.GetAxis("Horizontal")*speed, 0.0, Input.GetAxis("Vertical")*speed);

//reset jump because we are grounded

 jumpCount = 0;

     //ground dash once

if (dashCount < maxDash) { if (Input.GetKeyDown (KeyCode.X)) { moveDirection.x = dashSpeed; dashCount++;}

   //reset dash upon key release

 else if (Input.GetKeyUp (KeyCode.X))

{dashCount = 0;}}

 //reset dash when used midair (otherwise you would need to press and release

 X again; if you simply reset dash when on ground you end up dashing forever

 until you fall off platform

 else {dashCount = 0;}

 }

okay so that's what I have, the character only wants to dash forward because dashSpeed is a positive integer, and the arrow keys don't reflect positive or negative values. I'm not sure what I need to do to tweak it, but if there is some sort of scripting knowledge I'm unaware of I would love to hear lol. Thank you!

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 shane.rachel · Nov 07, 2012 at 12:19 AM

I had to use this: if (Input.GetKey (KeyCode.X) && Input.GetKey (KeyCode.LeftArrow)){ moveDirection = dashSpeed*-1;}

the function works now, thanks anyways though lol

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

9 People are following this question.

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

Related Questions

How do you double jump in a 2d game 1 Answer

why will my jump animation only play on multi-jumps? 0 Answers

problems with grounded and double jumping 2 Answers

Character Jump Problem! 0 Answers

Can not double jump when i fall off platform 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