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 WarLordYT · May 25, 2013 at 09:19 AM · speedsyntaxsprintno

Why Isn't This Sprint Working?

Why isnt this working? I can see NO syntax problems or incorrectly typed variable names? It just doesnt work, theres no errors or anything, it just doesnt work?

 var MoveSpeed = float;
 var RunSpeed : float = 4.0;
 var RunSpeed : float = 4.0;
 var SprintSpeed : float = 8.0;
 var JumpHeight : float = 6.0;
 
 var Gravity : float = 20.0;
 
 private var MoveDirection : Vector3 = Vector3.zero;
 
 private var ButtonA : boolean = false;
 private var ButtonD : boolean = false;
 private var ButtonS : boolean = false;
 
 
 
 function Start()
 {
     MoveSpeed = RunSpeed;
 }
 
 
 
 function Update()
 {
     var controller : CharacterController = GetComponent(CharacterController);
     
     if(Input.GetButton("A"))
     {
         ButtonA = true;
     }
     else
     {
         ButtonA = false;
     }
     
     if(Input.GetButton("D"))
     {
         ButtonD = true;
     }
     else
     {
         ButtonD = false;
     }
     
     if(Input.GetButton("S"))
     {
         ButtonS = true;
     }
     else
     {
         ButtonS = false;
     }
     
     
     
     if (controller.isGrounded)
     {
         MoveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
         MoveDirection = transform.TransformDirection(MoveDirection);
         MoveDirection *= MoveSpeed;
             
         if(Input.GetButtonDown("Sprint") && !ButtonA && !ButtonD && ButtonS)
         {
         MoveSpeed = RunSpeed * SprintSpeed;
         }
             
         if(Input.GetButtonUp("Sprint"))
         {
             MoveSpeed = RunSpeed;
         }
         
         if (Input.GetButton ("Jump"))
         {
             MoveDirection.y = JumpHeight;
         }
     }
     MoveDirection.y -= Gravity * Time.deltaTime;
 
     controller.Move(MoveDirection * Time.deltaTime);
 }
 
 
 
 function Sprint()
 {
     MoveSpeed = SprintSpeed;
 }
 
 
 
 function EndSprint()
 {
     MoveSpeed = RunSpeed;
 }
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 Graham-Dunnett · May 25, 2013 at 09:21 AM

So, the error message will include the line number where the compiler found the error. If you locate this line, it should be "obvious" what's wrong. I looked through the code quickly and didn't see a problem. Let the community know the line number if you need more help.

Comment
Add comment · Show 8 · 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 Graham-Dunnett ♦♦ · May 25, 2013 at 09:22 AM 0
Share

LOL. Posted that answer and immediately saw line 61. Try there.

avatar image Graham-Dunnett ♦♦ · May 25, 2013 at 09:35 AM 0
Share

Line 52 has a similar problem. (Please don't post an answer when you mean to make a comment.)

avatar image WarLordYT · May 25, 2013 at 09:45 AM 0
Share

line 65 now

avatar image WarLordYT · May 25, 2013 at 09:46 AM 0
Share

Its just calling on the Sprint function, but for some reason it finds a problem?

avatar image Hoeloe · May 25, 2013 at 11:32 AM 0
Share

I should also add that it's bad practice to end your if statements with semicolons, like this: if(Input.GetButtonUp("Sprint")); Now, I'm not sure how Javascript handles it, but a lot of program$$anonymous$$g languages treat that as an empty if statement, so a code block like this:
if(Input.GetButtonUp("Sprint")); { EndSprint(); } Will call EndSprint() regardless of the condition, because the condition is on the empty statement (i.e. ;), not on the block beneath it.

Show more comments

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

15 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

Related Questions

Decreasing footstep length when key pressed 1 Answer

Increase speed of footsteps when sprinting? 2 Answers

Energy Pickup 1 Answer

Sprint animation play ONLY when speed = 13 1 Answer

How do you make a sprint script actually change your speed? 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