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 CrilleStyles · Apr 17, 2014 at 09:12 AM · physicsscript errorsimple fix

What's wrong with this physicscript?

I've been trying to use the script I wrote but there is alot of errors. Can someone try to fix it?

 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;
 }   
Comment
Add comment · Show 3
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 Radivarig · Apr 17, 2014 at 09:17 AM 0
Share

What are the errors?

avatar image CrilleStyles · Apr 17, 2014 at 10:00 AM 0
Share

alt text Does this explaitn?

i don't know if this helps.png (81.4 kB)
avatar image Radivarig · Apr 17, 2014 at 10:06 AM 0
Share

Of course it helps :) it tells us exactly where the problem occurs. Always go from the top of the error report, check for the first error not $$anonymous$$ding the other errors since they get automatically generated because of the error before it. So, go to the line 48 and remove the "+" sign, save, then we will see what it says next

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by elpedro_75 · Apr 17, 2014 at 10:26 AM

The response above is spot on. Start from the top, and systematically work your way through the issues.

However, perhaps more importantly in this case (I am supposing) is the lack of regular testing prior to reaching this point. It would be rare indeed to have so many exceptions thrown in relation to a single addition. Even seasoned programmers make typing errors, logical errors (especially when they are tired), oversights, or they forget or confuse things (mixing programming languages, for example). It is prudent to test each and every addition to your code before moving on, unless that code is trivial. Use Unity's debug.log function. Ensure that your functions are being reached, ensure that the values and states are correct, and look for possible exceptions that may arise.

Following the above will possibly save you the shock encountering a seemingly endless string of problems. I hope that helps.

Comment
Add comment · 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

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix error BCE0005: Unknown identifier 1 Answer

2D 360 degress platformer example needed 0 Answers

Script isn't consistent 0 Answers

Trying to use colliders on trees to interact with player 1 Answer

Physics.SphereCastAll with triggers 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