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 Chimera3D · Jun 27, 2012 at 10:37 PM · physicsrigidbodyraycastforcehovercraft

Hovercraft Physics Problems

I've written my own hovercraft physics, however I can't seem to get it to work. I have Ray Position game objects that I place on different corners of the vehicle to dictate where the raycasts will go. These positions are then used to create the raycasts (going down), then determine where to add force on each corner of the object. I know I have nothing rotating or moving it forward, but what am I missing to get it off of the ground?

EDIT: Okay I figured out how to get it off of the ground with help from Wolfram, now it rocks and flips over a lot how can I fix that?

 #pragma strict
 
 var vehicleSpeed = 20;
 var rotationSpeed = 10.0;
 var airborneForce = 5.0;
 var offgroundHeight = 10.0;
 var startRotation : Quaternion;
 var startPosition : Vector3;
 var rayPos : GameObject[];
 
 function Start () {
     
     rayPos = GameObject.FindGameObjectsWithTag("RayPos");
     startRotation = transform.rotation;
     startPosition = transform.position;
     
 }
 
 function Update () {
     
     var down = transform.TransformDirection (-Vector3.up);
     
     var forwardForce : float = Input.GetAxis ("Vertical") * vehicleSpeed;
     
     var    flight = transform.TransformDirection (Vector3.up * airborneForce);
     
     rigidbody.AddForce (transform.forward * forwardForce);
     
     if(Input.GetAxis ("Horizontal")){
         
         var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
         transform.Rotate (0, rotation, 0);
         
     }
     
     if(Input.GetButtonDown("Jump")){
         rigidbody.drag = 50;
     }else
         
     if(Input.GetKeyDown("left ctrl")){
         transform.rotation = startRotation;
         transform.position.y += 2;
         rigidbody.drag = 50;
     }else
     
     if(Input.GetKeyDown("r")){
         transform.rotation = startRotation;
         transform.position = startPosition;
         transform.position.y += 2;
         rigidbody.drag = 50;
     }else
         
         rigidbody.drag = 0;
     
      if (Physics.Raycast (rayPos[0].transform.position, down, offgroundHeight)) {
              rigidbody.AddForceAtPosition(flight, rayPos[0].transform.position);
      }
      
      if (Physics.Raycast (rayPos[1].transform.position, down, offgroundHeight)) {
              rigidbody.AddForceAtPosition(flight, rayPos[1].transform.position);
      }
      
      if (Physics.Raycast (rayPos[2].transform.position, down, offgroundHeight)) {
              rigidbody.AddForceAtPosition(flight, rayPos[2].transform.position);
      }
      
      if (Physics.Raycast (rayPos[3].transform.position, down, offgroundHeight)) {
              rigidbody.AddForceAtPosition(flight, rayPos[3].transform.position);
      }
 
 }
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
1
Best Answer

Answer by Wolfram · Jun 27, 2012 at 10:53 PM

a) you are applying a downwards force to the rigidbody, but you need to apply an upwards force. Don't try to apply the "exhaust" from your hovercraft fans, apply the direction in which they would push your hovercraft: up.

b) note arrays start their count at 0, so if you have 4 objects tagged "RayPos", you'll need to access them using indices [0]..[3], not [1]..[4].

c) don't use any Find*-functions in Update, they are extremely slow. Assuming the amount/identity of objects tagged "RayPos" doen't change, do the FindGameObjectsWithTag() only once (i.e., in Start()). If the objects somehow do change, it might be a good idea to put the FindGameObjectsWithTag() in a separate function which is only called when they change.

EDIT: the script evolved while trying to solve all related problems, so the answer itself is rather outdated, but still contains hints to keep in mind. the rest of the answer is distributed in the comments ;-)

Comment
Add comment · Show 12 · 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 Chimera3D · Jun 27, 2012 at 11:07 PM 0
Share

I posted my updated script above, still not working...

avatar image Wolfram · Jun 27, 2012 at 11:39 PM 0
Share

Uh, wait, you are using "pos.rayPos[x]", which doesn't make any sense. pos is a Vector3, rayPos[x] is a GameObject. Does this even compile? Please add "#pragma strict" at the top of your script, to prevent mistakes like this.

Replace all occurences with this ins$$anonymous$$d: rayPos[x].transform.position

avatar image Chimera3D · Jun 27, 2012 at 11:44 PM 0
Share

Still not working.

avatar image Wolfram · Jun 27, 2012 at 11:51 PM 0
Share

Could you please update your question with your current script? Also, what exactly isn't working? Forward and rotation work? Doesn't it hover at all, or does it move/jump/jerk around?

avatar image Chimera3D · Jun 27, 2012 at 11:54 PM 0
Share

It doesn't hover at all. I'll post the current script.

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

What is the best way to apply force, then come to a smooth stop on control release? 1 Answer

Calculating required force for pushing a body to a desired position at once 0 Answers

increasing knockback of a rigidbody as received damage increases (like super smash) 1 Answer

Predicting land position with drag applied 0 Answers

Tornado throwing back force after pulling 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