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 /
This question was closed Oct 23, 2013 at 01:20 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by brandon199511 · Jan 02, 2012 at 06:26 AM · raycastterrainmovehitheight

Following Terrain Height?

EDIT: THE PROBLEM IS HIT.DISTANCE AS IT KEEPS CHANGING. I need it to be dynamic, but not be 2 things at once.

Is there a way to make an object go all the way down on the Y axis until it hits the terrain? As well as rotate with the curves?

I do not even know where to start with it , also I use javascript instead of C#, as I do not really know c#.

Extra info: I am instantiating an object, but using the code below, it just starts flickering from the instantiated place to the area the code calls for. The code below is all that is attached to the instantiated object.

Here is the code:

function Update () { var HighestPointOfTerrain : int = 50; var hit : RaycastHit; if(Physics.Raycast(transform.position, -Vector3.up, hit)) { var distancetoground = hit.distance; var heightToAdd = transform.localScale.y; transform.position.y = HighestPointOfTerrain - distancetoground+ heightToAdd; } }

Comment
Add comment · Show 7
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 rabbitfang · Jan 02, 2012 at 07:19 AM 0
Share

If you are looking for having it stay flush with the terrain, you will want to add a rigidbody component to the object.

avatar image brandon199511 · Jan 02, 2012 at 07:22 AM 0
Share

There is one added already.

avatar image rabbitfang · Jan 02, 2012 at 07:25 AM 0
Share

So then what is the problem? If the object has physics, it should stay on flush with the terrain automatically.

avatar image brandon199511 · Jan 02, 2012 at 07:27 AM 0
Share

I don't know any other way of saying that it flickers in two places

avatar image rabbitfang · Jan 02, 2012 at 07:34 AM 0
Share

By 'flickers' do you mean that is moving to multiple positions very rapidly?

I think the issue might be with the script moving the object to a bad location and then the physics engine pushes the object out of that location, the script puts it in another bad spot, and so on.

Show more comments

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by rabbitfang · Jan 02, 2012 at 07:42 AM

Try changing the line

 transform.position.y = HighestPointOfTerrain - distancetoground+ heightToAdd;

to

 transform.position.y = transform.position.y - distancetoground + heightToAdd;

Basically, what was happening was you were assuming that your object was always at a height of HighestPointOfTerrain (at least, that is what the code was doing), which caused your calculations to get messed up.

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 brandon199511 · Jan 02, 2012 at 07:54 AM 0
Share

You my friend are a life saver! Thank you so much!

avatar image rabbitfang · Jan 02, 2012 at 04:28 PM 0
Share

Then please mark my answer as correct (look for the check mark).

avatar image
0

Answer by kievar1983 · Jan 02, 2012 at 08:01 AM

are you looking to put an actual object on the ground or is this like a targeting box or something along those lines that you want to simply project onto the terrain. if it's the second idea, you might want to look into projections.

http://unity3d.com/support/documentation/Components/class-Projector.html

Comment
Add comment · Show 1 · 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 brandon199511 · Jan 02, 2012 at 08:16 AM 0
Share

The previous answer got what I needed. Works like a charm now :).

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Use OnTriggerEnter during a transform ! 0 Answers

Instantiated Objects not being set at ground/terrain level?(Solved) 1 Answer

rotation problems when snapping to terrain 1 Answer

Click to Move problem with hills 3 Answers

setting camera to hit.point returning null vector 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