- Home /
HoverCraft physics error
How can I fix this script, unity says "unexpected token.." and I can't see whats wrong?
var forwardPower:float;
var steerPower:float;
var landingPower:float;
var jumpingPower:float;
var hoverheight:float;
var stability:float = 1;
var body:GameObject;
public var speedUpdate:float;
private var hitNormal:Vector3[] = new Vector3[5];
private var rotation:Quaternion;
private var increment:float;
private var lastNormals:Vector3[] = new Vector3[5];
private var physicsSetup:boolean = false;
private var boxDim:Vector3;
private var cornerPoint:Vector3[] = new Vector3[5];
private var corners:Transform[] = new Transform[5];
private var boxCollider:BoxCollider;
private var yBounce:float;
private var lastPosition:Vector3;
private var distance:float;
private var average:Vector3;
function Awake(){
InitializePhysics();
}
function Update(){
CalculateSpeed();
}
function FixedUpdate(){
if(physicsSetup){
var hit:RaycastHit;
for(var i:int =0; i<corners.lenght-1; 1++) {
if(Physics.Raycast(corners[1].position,-corners[1].up,hit, hoverHeight+100)){
hitNormal[i] = body.transform.InverseTransformDirection(hit.Normal);
if(lastNormals[i] !=hitNormal[1]){
incrasement=0;
lastNormals[i] =hitNormal[i];
}
distance=hit.distance;
if(hit.distance < Hoverheight){
constantForce.relativeForce = (-avarage+transform.up) * rigitbody.mass * jumpingPower * rigitbody.drag * Mathf.Min(hoverHeight,hoverHeight/distance);
} else{
constantForce.relativeForce = (+transform.up) * rigitbody.mass * jumpingPower * rigitbody.drag * Mathf.Min(hoverHeight,hoverHeight/distance);
}
}
average = -(hitNormal[0] + hitNormal[1] + hitNormal[2] + HitNormal[3] + hitNormal[4])/2;
if (incrament !=1)(incrament ,=0.03;)
rotation = Quaternion.Slerp(BodyPart.transform.localRotation,Quaternion.Euler(average * Mathf.Rad2Deg),increment);
BodyPart.transform.localRotation = rotation;
BodyPart.transform.localRotation.y * Mathf.Deg2Rad;
var wdForce:float = Input.GetAxis("Vertical") * forwardPower;
rigitbody.AddForce (Transform.forward * fwdForce);
var steerForce:float = Input.GetAxis("Horisonental") * steerpower;
rigitbody.AddTorwue(ransform.up * steerForce);
}
}
function OnDrawGizmos(){
//Debugging corners positions.
if(corners[0] !=null) ( Gizmos.DrawWireSphere (corners[0].position, 1);)
if(corners[1] !=null) ( Gizmos.DrawWireSphere (corners[1].position, 1);)
if(corners[2] !=null) ( Gizmos.DrawWireSphere (corners[2].position, 1);)
if(corners[3] !=null) ( Gizmos.DrawWireSphere (corners[3].position, 1);)
if(corners[4] !=null) ( Gizmos.DrawWireSphere (corners[4].position, 1);)
}
function CalculateSpeed(){
if(lastPosition !=transform.position) {
var distance:float = Vactor3.Distance(transform.position, last Position);
speedUpdate = (distance/1000)/(Time.deltaTime/3600); //Km/h
}
}
function InitializePhysics(){
//Store the box dimension of hovering object.
boxCollider = body.AddComponent(BoxCollider);
boxDim = Vector3(boxCollider.size.x * body.transform.localstate.x boxCollider.size.y body.transform.localstate.y * boxCollider.size.z body.transform.localstate.z)
cornerPoint[0] = Vector3(transform.position.x-boxDim.x/2, transform.position.y -boxDim.y/2 , transform.position.z + boxDim.z/2);
cornerPoint[1] = Vector3(boxDim.x/2 + Transform.position.x, Transform.position.y -boxDim.y/2 , Transform.position.z + boxDim.z/2);
cornerPoint[2] = Vector3(boxDim.x/2 + Transform.position.x, Transform.position.y -boxDim.y/2 , Transform.position.z + boxDim.z/2);
cornerPoint[3] = Vector3(Transform.position.x/2, Transform.position.y -boxDim.y/2 , transform.position.z - boxDim.z/2);
cornerPoint[4] = Transform.position;
Destroy(boxCollider);
for (var i:int=0; i<=cornerpoint.lenght-1 i++){
var stablePlatfom:GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
stablePlatform.name="stableplatform" + "(" + 1 + ")";
stablePlatform.transform.parent = body.transform;
stablePlatform.transform.localPosition = transform.InverseTransformPoint(cornerPoint[i]);
corners[i] = stablePlatform.transform;
Destroy(stablePlatform.GetComponent (MeshRenderer));
Destroy(stablePlatform.GetComponent(Collider));
}
cornerPoint=null;
physicsSetup = true;
}
Answer by Lachee1 · Apr 13, 2014 at 07:53 AM
You forgot the ';' in your InitializePhysics function, on the line
boxDim = Vector3(boxCollider.size.x * body.transform.localstate.x boxCollider.size.y body.transform.localstate.y * boxCollider.size.z body.transform.localstate.z)
it should be
boxDim = Vector3(boxCollider.size.x * body.transform.localstate.x boxCollider.size.y body.transform.localstate.y * boxCollider.size.z body.transform.localstate.z);
If you give the error code line, it would be faster to figure out were it went wrong next time.
edit: its on line 88, assuming they are accurate line numbers on the posted code
edit: You are also using ( ) on your if statements, its has to be { } brackets
function OnDrawGizmos(){
//Debugging corners positions.
if(corners[0] !=null) ( Gizmos.DrawWireSphere (corners[0].position, 1);)
if(corners[1] !=null) ( Gizmos.DrawWireSphere (corners[1].position, 1);)
if(corners[2] !=null) ( Gizmos.DrawWireSphere (corners[2].position, 1);)
if(corners[3] !=null) ( Gizmos.DrawWireSphere (corners[3].position, 1);)
if(corners[4] !=null) ( Gizmos.DrawWireSphere (corners[4].position, 1);)
}
should be
function OnDrawGizmos(){
//Debugging corners positions.
if(corners[0] !=null) { Gizmos.DrawWireSphere (corners[0].position, 1);}
if(corners[1] !=null) { Gizmos.DrawWireSphere (corners[1].position, 1);}
if(corners[2] !=null) { Gizmos.DrawWireSphere (corners[2].position, 1);}
if(corners[3] !=null) { Gizmos.DrawWireSphere (corners[3].position, 1);}
if(corners[4] !=null) { Gizmos.DrawWireSphere (corners[4].position, 1);}
}
line 88, assu$$anonymous$$g they are accurate line numbers on the posted code
Im sorry, im not sure. You just have to carefully go over your code and check for syntax errors you may of accidently made.
Your answer
Follow this Question
Related Questions
How do I make a first person player get in a vehicle? 0 Answers
Parenting player to car on click. 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Scripting "physics"? 1 Answer
Car physics inverted? 0 Answers