- Home /
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:
"Assets/RigidbodyPlayerController.js(47,10): BCE0044: expecting (, found 'OnCollisionExit'."
"Assets/RigidbodyPlayerController.js(47,27): BCE0043: Unexpected token: collisionInfo."
"Assets/RigidbodyPlayerController.js(47,53): UCE0001: ';' expected. Insert a semicolon at the end."
"Assets/RigidbodyPlayerController.js(49,20): BCE0044: expecting :, found '='."
Making changes based on the debug clues are coding nonsense. Am I missing something here?
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!
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).
Thanks a lot. I feel like a fool now; I thought I had checked all the brackets. I really appreciate the help!
Your answer
Follow this Question
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