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 cyoder · Feb 07, 2013 at 04:05 AM · collisionerrorcompilingoncollisionexit

Strange compiler errors with OnCollisionExit

I'm having strange compiler errors when trying to compile a script for player controls using rigidbodies. I've looked around for some other answers, but no one else seems to have this problem. I am a newbie at scripting/programming, so I hope it's not an obvious mistake.

Anyway, I've been more or less copying code from this tutorial page, but I'm getting errors that make no sense to me. Here's the script (RigidbodyPlayerController.js):

 #pragma strict
 
 public var speed : float = 5.0;
 public var moveDirection : Vector3 = Vector3.zero;
 public var jumpDirection : Vector3 = Vector3.zero;
 public var jumpSpeed : float = 500.0;
 public var isGrounded : boolean = false;
 public var jumping : boolean = false;
 public var inAir : boolean = false;
 public var airControl : float = 0.5;
 public var jumpClimax : boolean = false;
 
 function Movement () {
 if(Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
     {
         moveDirection = Vector3(Input.GetAxisRaw("Horizontal"), moveDirection.y, Input.GetAxisRaw("Vertical"));
         this.transform.Translate((moveDirection.normalized * speed) * Time.deltaTime);
     }
     if(Input.GetButtonDown("Jump") && isGrounded) 
     {
         jumping = true;
         jumpDirection = moveDirection;
         rigidbody.AddForce((transform.up) * jumpSpeed);
     }
     if (isGrounded) 
     this.transform.Translate((moveDirection.normalized * speed)*Time.deltaTime);
     else if (jumping || inAir)
     this.transform.Translate((jumpDirection * speed * airControl)*Time.deltaTime);
 }
 
 function FixedUpdate () {
 if (!isGrounded) {
     if(Physics.Raycast(transform.position, -transform.up, collider.height/2 + 0.2))
     {
         isGrounded = true;
         jumping = false;
         inAir = false;
     }
     else if (!inAir)
     {
         inAir = true;
         jumpDirection = moveDirection;
     }
 Movement ();
 }
 
 function OnCollisionExit (collisionInfo : Collision) // line 47, first three errors
 {
     isGrounded = false; // line 49, forth error
 }
 
 function OnCollisionStay (collisionInfo : Collision)
 {
     contact = collisionInfo.contacts[0];
     if (inAir || jumping)
     {
         rigidbody.AddForceAtPosition(-rigidbody.velocity, contact.point);
     }
 }

The errors that I get (pertaining to OnCollisionExit) are these:

  1. "Assets/RigidbodyPlayerController.js(47,10): BCE0044: expecting (, found 'OnCollisionExit'."

  2. "Assets/RigidbodyPlayerController.js(47,27): BCE0043: Unexpected token: collisionInfo."

  3. "Assets/RigidbodyPlayerController.js(47,53): UCE0001: ';' expected. Insert a semicolon at the end."

  4. "Assets/RigidbodyPlayerController.js(49,20): BCE0044: expecting :, found '='."

Making changes based on the debug clues are coding nonsense. Am I missing something here?

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

Answer by golden pouria · Feb 07, 2013 at 04:56 AM

You need to add a "}" character to the line 46. So it will be like:

 ....... blah blah blah blah
 44. Movement ();
 45. }
 46. } //this one is missing
 47. function OnCollisionExit (collisionInfo : Collision) // line 47, first three errors
 48. {
 49. isGrounded = false; // line 49, forth error
 50. }
 ....... blah blah blah blah

this will solve all of your errors (hopefully)...

Have Fun!

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 Eric5h5 · Feb 07, 2013 at 05:25 AM 1
Share

Indeed, this is why it's important to format code properly and be consistent with indentation, so you can easily see where the problem originates. The compiler doesn't have any advanced AI and can only tell you what it expects considering what you gave it (i.e., it can't interpret what you meant, only what you wrote).

avatar image cyoder · Feb 07, 2013 at 03:09 PM 0
Share

Thanks a lot. I feel like a fool now; I thought I had checked all the brackets. I really appreciate the help!

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

11 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

Related Questions

Compiler error while trying to access a Collider's script. 1 Answer

compilling error?... 1 Answer

OnTriggerEnter NullReferenceException 0 Answers

Deal Damage On Collision 3 Answers

Go To new Scene Button! 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