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 MadMAus · Aug 15, 2013 at 03:53 PM · gameprogramming

Unable to find problems with 2d-scrolling movement code.

So I have been trying today to learn both a bit of coding and have to make my own game. I have been following this guys tutorials: http://www.youtube.com/user/TDCnoho?feature=watch but I am now stock on Episode 6, where I am making a sidescroller, and learning how to make the movement.

I tried to rip off the script directly from his video which can be found at 4:00, and what I have is:

 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 - function Update(){;
     var controller : CharacterController = Getcomponent(CharacterController)
 -    If (controller.isGrounded) {
         // We are grounded. so recalculate
         // move direction directly from axes
         moveDirection = Vector3(0,0,Input.GetAxis('Horizontal*'));
         //moveDirection = transform.TransformDirection(moveDirection);
         //controller.transform.LookAt();
         moveDirection *= speed;
 
     if (moveDirection.sqrMagnitude > 0.01)
         transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(moveDirection),1);
 
 
 -        if(Input.GetButton ('Jump')) {
             moveDirection.y = jumpSpeed;
         }
     }
 
     // Apply gravity
     moveDirection.y -= gravity*Time.deltaTime;
     // Move the controller
     controller.move(moveDirection*Time.deltaTime);

I keep getting errors though,which are as following:

  1. Assets/Platformer Movement.js(7,12): BCE0044: expecting (, found 'Update'.

  2. Assets/Platformer Movement.js(7,20): UCE0001: ';' expected. Insert a semicolon at the end.

  3. Assets/Platformer Movement.js(9,35): UCE0001: ';' expected. Insert a semicolon at the end.

  4. Assets/Platformer Movement.js(21,17): BCE0043: Unexpected token: if.

  5. Assets/Platformer Movement.js(21,19): UCE0001: ';' expected. Insert a semicolon at the end.

  6. Assets/Platformer Movement.js(21,45): UCE0001: ';' expected. Insert a semicolon at the end.

  7. Assets/Platformer Movement.js(30,1): BCE0044: expecting }, found ''.

All of these errors, and I have gone in and tried to alter it several times, but I cannot find the problem, or the difference in his and mine.

Comment
Add comment · Show 1
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 MadMAus · Aug 15, 2013 at 04:05 PM 0
Share

I just copied everything from the video, and that was how it looked. Changing it seems to do little in relation to the errors I am getting.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Linus · Aug 15, 2013 at 03:55 PM

function Update(){; should not have ; at the end

var controller : CharacterController = Getcomponent(CharacterController) should have ;

You are missing a } at the very end

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 MadMAus · Aug 15, 2013 at 04:05 PM 0
Share

I changed that, and it helped nothing. :/

avatar image
0

Answer by robertbu · Aug 15, 2013 at 04:01 PM

In addition to the problems that @Linus lists, pay close attention to the case of letters.

  • 'move' is not 'Move'

  • 'Getcomponent' is not 'GetComponent'

  • 'If' is not 'if'

In the console window, the first error is generally accurate (though the actual error is often on the preceding line). So the way to fix syntax errors is to click on the topmost error in the console window, Go to Mono and fix it, then go back to Unity and select the new topmost error, go back to Mono and fix the next error... Here is your script with all the syntax errors fixed:

 #pragma strict
 
 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update(){
     var controller : CharacterController = GetComponent(CharacterController);
        if (controller.isGrounded) {
        // We are grounded. so recalculate
        // move direction directly from axes
        moveDirection = Vector3(0,0,Input.GetAxis('Horizontal*'));
        //moveDirection = transform.TransformDirection(moveDirection);
        //controller.transform.LookAt();
        moveDirection *= speed;
 
     if (moveDirection.sqrMagnitude > 0.01)
         transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(moveDirection),1);
 
      if(Input.GetButton ('Jump')) {
          moveDirection.y = jumpSpeed;
        }
     }
 
     // Apply gravity
     moveDirection.y -= gravity*Time.deltaTime;
     // Move the controller
     controller.Move(moveDirection*Time.deltaTime);
 }
Comment
Add comment · Show 5 · 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 MadMAus · Aug 15, 2013 at 04:11 PM 0
Share

I just copied everything from the video, and that was how it looked. Changing it seems to do little in relation to the errors I am getting.

avatar image robertbu · Aug 15, 2013 at 04:15 PM 0
Share

I seriously doubt your script is the way it looked in the video. Compare the fixed one above to the video.

avatar image MadMAus · Aug 15, 2013 at 08:41 PM 0
Share

Hey, I have tried adding this, and it doesn't give me the coding errors anymore, but now I get this error:

'NullReferenceException: Object reference not set to an instance of an object Platformer $$anonymous$$ovement.Update () (at Assets/Platformer $$anonymous$$ovement.js:9)'

avatar image robertbu · Aug 15, 2013 at 09:00 PM 0
Share

This code expects a character controller. Select the object this script is attached to, then:

Component > Physics > Character Controller

avatar image MadMAus · Aug 15, 2013 at 09:12 PM 0
Share

UnityException: Input Axis Horizontal* is not setup. To change the input settings use: Edit -> Project Settings -> Input Platformer $$anonymous$$ovement.Update () (at Assets/Platformer $$anonymous$$ovement.js:12)

And now I get this. haha, im terrible at this.

Thank you so much for your patience and your helpfulness.

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

16 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

Related Questions

Multiple Cars not working 1 Answer

How do you script in Java? Anyone have some exaple codes I could use? 0 Answers

I'm having troubles using a Capsule Cast 2 Answers

Programming in Unity 2 Answers

Delay for jumping, I've looked everywhere. 2 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