• 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 Vioswift · Sep 06, 2015 at 10:01 AM · rotationterrainslopeoncontrollercolliderhit

Unity 3D C# - OnControllerColliderHit Position

Hi Im trying to move an object and keep its rotation which the slope of the terrain, for example, when the object goes up a hill, the object rotation changes with it and doesn't stay vertical, this is my code which are failed attempts.

  void OnControllerColliderHit(ControllerColliderHit hit) {
         //myAng = Vector3.Angle(Vector3.up, hit.normal); //Calc angle between normal and character
         //transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal) * transform.rotation;
         //transform.Rotate(Vector3.up * Time.deltaTime * 6f);
 
         //transform.rotation = Quaternion.Euler(new Vector3(hit.transform.rotation.x, transform.rotation.y, hit.transform.rotation.z));
 
         transform.rotation = Quaternion.LookRotation(new Vector3(hit.transform.position.x, transform.rotation.y, hit.transform.position.z));
     }
Comment
Add comment · Show 1
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 getyour411 · Sep 22, 2015 at 02:51 AM 0
Share

Little confused - do you expect A) the object to stay perfectly vertical and not change rotation/tilt or B) mimic the slope of the terrain?

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make an instantiated object match the slope of the terrain 1 Answer

Unity automatically rotate camera on slopes up/down 0 Answers

slope detection 3 Answers

How do I make my object follow the ground perfectly? 1 Answer

rotating gameobject according to terrain before instantiate 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges