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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by HiddenKiller7 · Jul 30, 2013 at 06:37 AM · movement script

Sprint Script??

I need Help wrighting a script to make the player sprint ive added this :

if (Input.GetKeyDown(KeyCode.LeftShift));

     (maxForwardSpeed == 15.0); 

Into the Character motor (script) on unity premade scripts and it wont work :(

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by tw1st3d · Jul 30, 2013 at 06:46 AM

 function Update()
 {
     if(Input.GetKeyDown(KeyCode.LeftShift));
         maxForwardSpeed = 15.0; 
     else
         maxForwarSpeed = 10.0;
 }

try putting in an Update() function in the script. I've never really dealt with modifying a script that wasn't mine, so I don't know if there's a smarter way to change it other than adding it into the file itself, another member could answer that. Anyway, you also forgot to add in an else statement to set it back to normal. So, here you go.

Comment
Add comment · Show 1 · 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 rASS_k · Mar 26, 2018 at 05:54 PM 0
Share

Old thread I know but this helped. Just thought I'd say however, that $$anonymous$$es didn't work with "Get$$anonymous$$eyDown", had to just use "Get$$anonymous$$ey" ins$$anonymous$$d (just for anyone else who comes across this in the future!).

avatar image
0

Answer by save · Jul 30, 2013 at 06:47 AM

You should not end your if-statement with semicolon, what probably has confused you is that you don't need braces for an if-statement if you only have one operation depending on it.

 // Example without braces
 if (Input.GetKeyDown(KeyCode.LeftShift))
     maxForwardSpeed = 15.0;

 // Example with braces
 if (Input.GetKeyDown(KeyCode.LeftShift))
 {
     maxForwardSpeed = 15.0;
 }

Another thing is that (maxForwardSpeed == 15.0) is a boolean operation, maxForwardSpeed = 15.0 will assign 15.0 to the variable.

For additional help on adding a run function to your character controller please see How to Make the FPS Character RUN and CROUCH.

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 tw1st3d · Jul 30, 2013 at 06:50 AM 0
Share

Actually, if statements only need brackets if they're calculating one operation in its scope, example

 if(condition)
    if(condition2)
       if(condition3)
       {
          operation1;
          operation2;
       }

Otherwise, good answer.

avatar image save · Jul 30, 2013 at 06:59 AM 0
Share

Thanks @tw1st3d for making my slurred expression more evident. :-)

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

17 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

Related Questions

Jerky movement of the object 0 Answers

How to change movement script for computer for android. 1 Answer

isGrounded is always false, even with gravity, how do you fix that? 1 Answer

Why wont my attack script get the data from my movement script (error)? 1 Answer

What is the best method to control the movement of a group of objects based on the collision trigger of any individual? 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