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
-2
Question by AnaRhisT · Jun 21, 2010 at 07:41 PM · rotationgameobjectterrainnormals

Bound the gameobject from the ground

Hey guys! Here's a complicated task I cannot solve and looking forward to get ur help!

Picture of what I want to get done : http://img180.imageshack.us/i/hitpoint.jpg/

Description : I've a character, When I left click with my mouse on the Terrain the GameObject(Also called - HitPoint) goes to the hit.point position that was casted from the Mouse's position. and that HitPoint gameobject goes there with his 0,0,0 rotation. and I want it to be rotated like 180 degrees from the terrain. -Because I cannot explain exactly what I mean about rotating it like 180 degrees from the terrain the picture will make sure u understood it right. On the beginning I did this :

var HitPoint : Transform;
movePosition = hit.point;
HitPoint.transform.position = movePosition;

Now I need to rotate the HitPoint's.transform.rotation somehow. Thanks in advance!

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
-2

Answer by qJake · Jun 21, 2010 at 10:27 PM

If you have a terrain called "myTerrain", you can set the rotation of the object "myObject" (your cylinder) using this:

myObject.rotation = Quaternion.LookRotation(
     myTerrain.terrainData.GetInterpolatedNormal(
          myObject.transform.position.x / myTerrain.terrainData.size.x,
          myObject.transform.position.z / myTerrain.terrainData.size.z
     )
);

I've never actually done this before, so it's kind of a guess, but I'm fairly certain you do need to use GetInpterpolatedNormal(). If this exact code doesn't work, perhaps you can tweak it and figure it out yourself.

Also, this code doesn't use hitpoints for the purposes of making it more generic. This will actually work inside of Update(), and will cause "myObject" to always rotate with whatever direction the normal is at that point on the terrain.

Comment
Add comment · Show 4 · 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 AnaRhisT · Jun 21, 2010 at 10:46 PM 0
Share

nope, doesn't work it's like the 0,0,0 is 40,0,0 .. 40 degrees on the x-axis..

avatar image AnaRhisT · Jun 21, 2010 at 10:56 PM 0
Share

this is what i mean when i say 40 degrees on the x-axis : http://img130.imageshack.us/img130/6291/40degrees.jpg

avatar image AnaRhisT · Jun 21, 2010 at 11:02 PM 0
Share

another one http://img227.imageshack.us/img227/6291/40degrees.jpg

avatar image AnaRhisT · Jun 22, 2010 at 09:06 AM 0
Share

I also tried.. with a ray the normals..

movePosition = hit.point; normalPosition = hit.normal; HitPoint.transform.position = movePosition; HitPoint.transform.LookAt(HitPoint.transform.position + HitPoint.transform.forward, normalPosition);

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

Rotation Transform to face character AND normal to terrain 2 Answers

C# Rotate GameObjects Regardless of List Size 2 Answers

working with RotateArround 2 Answers

(Solved) Aligning player to surface while still maintaining look direction 1 Answer

Rotating a GameObject based on another GameObject's y-axis 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