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 user-3061 (yahoo) · Feb 03, 2011 at 02:54 PM · distanceracingfloatinghovering

Maintain height/Altitude/distance from ground?

Hi, How can i make something maintain a certain distance between the ground and the player? ( something like a hovercraft ) I tried raycasting below the object and adding force to it when its lower than a certain distance, but it looks odd with the bumping and its not very smooth since i wanted to move the object around, like a racing game. THANKS!

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

2 Replies

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

Answer by PrimeDerektive · Feb 03, 2011 at 04:26 PM

I would probably do what you mentioned in your original answer. Did you do it right? I guess I would do something like this (not tested):

var height: float = 5.0; var forceMultiplier : float = 10.0;

function FixedUpdate(){

 var hit : RaycastHit;

 if(Physics.Raycast(transform.position, -transform.up, hit, height)){
     rigidbody.AddForce(transform.up*(forceMultiplier/(hit.distance/2)));
 }

}

Some Notes:

1) I'm using FixedUpdate(), don't forget to use FixedUpdate() for applying rigidbody forces.

2) Make sure you set freeze rotation on the rigidbody.

3) By dividing forceMultipler by (hit.distance/2), I am attempting to apply a force relative to the length of the ray (the height off the ground). So the lower the hovercraft goes, the more upward force is applied to balance it out. This was just a crappy theory, I'm no math whiz, but I played around with some different numbers and this looks pretty good. You could try tweaking it or just changing the formula and see what happens.

Comment
Add comment · Show 2 · 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 user-3061 (yahoo) · Feb 04, 2011 at 04:59 AM 0
Share

same like the comment above

avatar image PrimeDerektive · Feb 04, 2011 at 02:13 PM 1
Share

Hmm, I think you're pretty much relegated to doing what you mentioned in your original post. How did you do it though? See my updated answer as to how I would probably do it.

avatar image
0

Answer by Senhor de todo o Mal · Feb 03, 2011 at 03:39 PM

There are two ways I can see to do this.

You can either add a character controller that extends a bit downward, then use Move and/or SimpleMove to move around.

Or you can add a collider, set it as trigger and add upwards force if it hits the ground:

function OnTriggerEnter(other:Collider){ // if other == floor start applying upwards force }

function OnTriggerEnter(other:Collider){ // if other == floor stop applying upwards force }

Comment
Add comment · Show 2 · 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 user-3061 (yahoo) · Feb 04, 2011 at 04:59 AM 0
Share

i didnt want the hovercraft to just " appear " floating by using a collider, i wanted the controller to lift and move dynamically according to the terrain/area condition,(eg : lifting from a lower ground to a higher stair ) not faking it.

avatar image Senhor de todo o Mal · Feb 04, 2011 at 10:18 AM 0
Share

I'm not quite understanding. If you want it to bob, the trigger collider will do just fine, it's just a trigger with no collisions, when it is triggered by the floor you add upwards force, there won't be a snapping effect, it will give a sort of bobbing motion.

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

No one has followed this question yet.

Related Questions

Comparing values of an array 1 Answer

how to display distance in scene 2 Answers

Should i use terrain generation or make it myself for android? 0 Answers

Script Conversion JS to C# 3 Answers

how to script a timed GUI Label into my script 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