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 barkermn01 · Nov 01, 2013 at 03:16 PM · physicsforceracing

Hovering Ship glued to a Track C#

Hello,

I'm new to unity and i have to use it for a unity project but i'm at a loss with what i need to do Programmaticly i know how to do it but in unity i have no idea if what i have planned would even work and if it would how i get the properties i need.

I currently have my Ship hovering effect by using a force to offset gravity

 public float HoverThrust = 9.81f;
 private bool hoverPush = false;
 
 void FixedUpdate() 
 {    
         if(HoverThrust > 9.85f || HoverThrust < 9.78f){
             hoverPush = !hoverPush;
         }
         HoverThrust = (hoverPush)? HoverThrust+0.02f : HoverThrust-0.02f;
         
         rigidbody.centerOfMass = new Vector3(-0.2f, 0, 0);
         
         Vector3 centralThrusterPosition, centralThrusterForce;
         centralThrusterPosition = new Vector3(
             transform.position.x-0.2f,
             transform.position.y,
             transform.position.z
         );
         centralThrusterForce = new Vector3( 0, HoverThrust, 0);
         
         rigidbody.AddForceAtPosition(centralThrusterForce, centralThrusterPosition);
 }

This works and gives me a (mild)hovering effect but as you can see its using gravity force amounts to counter Gravity i want it so i counter gravity by pushing off a track below however it would need to be the track directly below the ship as there will be loop the loops and such

Comment
Add comment · Show 2
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 Fornoreason1000 · Nov 01, 2013 at 03:37 PM 0
Share

this is a simple Physics problem, -9.8 + 9.8 = 0, therefore your velocity is zero. you are indeed hovering you need to add a small amount of extra force to get it off the ground initially(a burst).

Raycasting will also help on the staying on track regard, its just a matter of angles and raycasting as you go around.

avatar image barkermn01 · Nov 04, 2013 at 03:43 PM 0
Share

Thanks for that that makes sence but the big problem i have understand i'm hovering but as i said i'm hovering by pushing from my Object against gravity not against the object below the ship $$anonymous$$G i have Ship 1 Y above Plane the ship is pushing from the gravity not from the plane is it possible to push and messure from the plane and not just the whole wold?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Huacanacha · Nov 04, 2013 at 04:21 PM

It sounds like you should Raycast downwards from your hovercraft to see if it hits the track. Check out: http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

The third version of the function, with the layerMask, would allow you to only test for collisions against a 'track' layer that you could set up. This would avoid any interference with other objects in your scene that shouldn't be used as hover platforms.

Assuming you hover engines have a maximum range of 10 meters (could be anything!), the raycast call would be something like:

 Physics.Raycast(transform.position, Vector3.down, 10, layerMask)

If you want to check 'downwards' based on the vehicles orientation use:

 Physics.Raycast(transform.position, -transform.up, 10, layerMask)

If you then want to apply the hover force based on the vehicles orientation calculate the force to apply like this:

 Vector3 hoverForce = transform.up * HoverThrust;

If you want to check for the track existing under a larger area of the vehicle you could either run multiple Raycasts at the extents of your vehicle or use a SphereCast with a reasonable radius.

By collecting the RaycastHit (the second set of three Raycast methods) you can also apply the thrust force based on the track orientation:

 Vector3 hoverForce = hitInfo.normal * HoverThrust;

Either of these two options will cause the vehicle to slide down and thrust sideways when either the vehicle or track aren't perfectly horizontal. You could either allow this as a cool effect or counter it by fixing the Y thrust to 9.81.

If you want to make the hover thrust force proportional to the distance from the track you could use the the Raycast methods that give HitInfo to get the distance, then use whatever formula you want to calculate the force. This could give you a very easy way to make the vehicle rise from the track to the desired hover height... a very simple example for a desired hover height of 2 (higher than gravity force close to the track, less than gravity force further than 2 meters away from track):

 float hoverThrust = 9.81f * 2/Mathf.Clamp(hitInfo.distance, 0.5f, 4f);
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

17 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

Related Questions

Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers

Make object stick to the ground in 2D 2 Answers

ForceMode.Acceleration estimated dst != covered dst with a single Addforce in effect 1 Answer

How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers

Molecule simulation: make child objects attract each other so parents will stay close together? 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