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 Davinel · Aug 05, 2013 at 07:41 PM · camerarotationterrainslope

Unity automatically rotate camera on slopes up/down

I have a Player in first person walking around on terrain and I'd like to restrict the camera controls to the y axis (left/right) and automate the camera rotation of the x axis. So looking up/down should require no player input, depending on wether you walk up a slope or down.

I'm not quite sure what to look for. You could probably do it with a Raycast, but I suppose there's an easier way?

Comment
Add comment · Show 3
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 robertbu · Aug 05, 2013 at 08:53 PM 0
Share

You've provided too few details for a complete answer. How you might organize this will depend on factors like how you allowing your character to move. Raycasting is likely necessary to get the normal to align the character with the slop. The critical like of code that I think will allow you to do what you want is:

 transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;

This will assure that the up vector of your transform is aligned, but it will allow you to rotate the block along it's local 'Y' axis.

avatar image Davinel · Aug 06, 2013 at 01:33 AM 0
Share

Yes, I should have wrote that I use a Character Controller for movement. Well I can detect going uphill with a Raycast, but how would I look down again after you reach the top? Set one raycast on the upper part of the screen to detect when to move the camera up and one on the lower part of the screen to detect when to move it down?

avatar image robertbu · Aug 06, 2013 at 01:50 AM 0
Share

I'm not sure of your goal here, but a Raycast() will detect the normal to the mesh under the character. Just so I'm sure we are talking about the same thing, here is an image:

alt text

Each ray would be the normal at that point on the surface. Whether your camera would be tilted up, or down, would depend on your rotation with respect to that normal. At the top of the hill, the camera would be level because the normal points straight up (and my suggested code aligns the 'y' axis of the object with the normal).

For your game mechanic, you may have a specific restrictions, or behaviors. But you'd have to spell them out in order for anyone here to offer you a specific solution.

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.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Camera Follow Code Causes Jerky Movements 2 Answers

How to make the camera rotate only when right click is held down on the mouse? 1 Answer

Making a particle effect parallel to the slope of a terrain 1 Answer

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

Unity 3D C# - OnControllerColliderHit Position 0 Answers


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