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
1
Question by Ryoni · Dec 05, 2010 at 07:13 PM · terrainmovingsurface

Moving along surface without physics?

If I want to keep my game light without hundreds of objects using physics, how would I make my enemies move along the terrain if it's not 100% flat? I'm looking for some way to just set "enemy.position.y = terrain height below the enemy" or anything as simple.

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

Answer by Eric5h5 · Dec 05, 2010 at 07:26 PM

If it's an actual Unity terrain, use Terrain.SampleHeight().

Comment
Add comment · Show 6 · 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 Ryoni · Dec 05, 2010 at 09:05 PM 0
Share

Could you give some example how to use it? transform.position.y = Terrain.activeTerrain.SampleHeight(transform.position); Didn't work

avatar image Ryoni · Dec 05, 2010 at 09:41 PM 0
Share

height = Terrain.activeTerrain.SampleHeight(transform.position); transform.position = new Vector3(transform.position.x, height, transform.position.z); Seems to work but my enemy rotation gets messed up and howers like 20 meters on ground. Strange..

avatar image Ryoni · Dec 06, 2010 at 02:22 PM 0
Share

Still can't get this working. "Cannot movide a value type return value of 'UnityEngine.Transform.position' Consider storing the value in temporary variable"? Both the enemy transform and height from SampleHeight are in temporary variables. What I'm still supposed to do?

avatar image Eric5h5 · Dec 06, 2010 at 04:18 PM 0
Share

Use Javascript ins$$anonymous$$d of C#, in which case you aren't required to manually store values in temporary variables when you just want to modify transform.position.y. ;) Other than that I couldn't say without knowing what you're doing.

avatar image Ryoni · Dec 07, 2010 at 10:37 AM 0
Share

Apparently it works now with C# but the height given with SampleHeight is incorrect for some reason. $$anonymous$$y enemy is at 197 on y axis, the terrain is 2 units lower at 195 and after setting my enemy's y axis to terrain height gotten from SampleHeight the result is 217. I'd like to have some example. No idea what I'm doing wrong.

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

No one has followed this question yet.

Related Questions

Too many texture interpolators would be used for ForwardBase pass (again) 1 Answer

CG diffuse shader 1 Answer

Moving a point along a plane, mesh, or collider 1 Answer

Make a simple tree 1 Answer

Walls not moving in 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