Thanks for the advice. Deleted the script and rewrote its contents as a function in the script that controls the moving rigid body.Still the same problem :S.
I’ve copied and pasted the whole thing below. Its functional but a bit of a skeleton as I’m trying to sort out the camera before working on the other bits.
private var camx = 0;
private var camy = 0;
private var camz = 0;
private var avatarx = 0;
var levelstartx = 0;
var levelstarty = 0;
var levelendx = 0;
var levelendy = 0;
var GameCamera : GameObject;
camx = GameCamera.transform.position.x;
camy = GameCamera.transform.position.y;
camz = GameCamera.transform.position.z;
var velocity = 20;
var jump = 10000;
private var gravity = -9.8f;
rigidbody.useGravity = false;
rigidbody.velocity = Vector3(velocity*1,0,0);
function Update () {
Debug.Log(Platform_status());
switch(Platform_status())
{
//When on floor
case “floor”:
//remove any bounce
rigidbody.velocity.y = 0;
//Left Key
if (Input.GetButton (“Left”)) {
rigidbody.velocity.x = velocity*-1;
}
//Right Key
else if (Input.GetButton (“Right”)) {
rigidbody.velocity.x = velocity*1;
}
//Up Key
else if (Input.GetButton (“Up”)) {//
rigidbody.velocity.y +=7;
}
//Down Key
else if (Input.GetButton (“Down”)) {
//crouch code here
}
break;
//When on Ceiling
case “ceiling”:
//remove any bounce
rigidbody.velocity.y = 0;
//Left Key
if (Input.GetButton (“Left”)) {
rigidbody.velocity.x = velocity*-1;
}
//Right Key
else if (Input.GetButton (“Right”)) {
rigidbody.velocity.x = velocity*1;
}
//Up Key
else if (Input.GetButton (“Up”)) {//
//crouch code here
}
//Down Key
else if (Input.GetButton (“Down”)) {
rigidbody.velocity.y -=7;
}
break;
//When Wall to the right
case “right_wall”:
break;
//When Wall to the left
case “left_wall”:
break;
//When in air
case “midair”:
//apply gravitational force
rigidbody.velocity.y += gravity * Time.deltaTime;
break;
}
Camera_Control();
}
function Platform_status() : String {
var hit : RaycastHit;
var platform : String;
if (Physics.Raycast (transform.position, Vector3.up,1)){
platform = “ceiling”;
}
else if (Physics.Raycast (transform.position, Vector3.down,1)){
platform = “floor”;
}
else if (Physics.Raycast (transform.position, Vector3.right,1)){
platform = “right_wall”;
}
else if (Physics.Raycast (transform.position, Vector3.left,1)){
platform = “left_wall”;
}
else {
platform = “midair”;
}
return platform;
}
function Camera_Control(){
if ( transform.position.x > levelstartx transform.position.x < levelendx){
camx = transform.position.x;
}
if (transform.position.y > levelstarty transform.position.y < levelendy){
camy = transform.position.y;
}
GameCamera.transform.position = Vector3(camx, camy , -60);
}