• 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
Question by DavidDebnar · Apr 13, 2012 at 07:21 PM · rotationplayerrotation axisfloor

Rotate player towards the floor

Hey guys! I need a script that will rotate the player towards the floor angle. I have been googling a lot, but I could not find anything I could use.

Ok, so what I need to do is rotate the player from

Image 1

to

alt text

The red arrows are indicating the direction the player will move.

Is there any way to do this?

  • David

rotatePlayer1.png (948 B)
rotatePlayer1.png (922 B)
Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by AlucardJay · Apr 13, 2012 at 07:37 PM

Try raycasting down, then reading the 'normal' of the floor. Then rotate the player to match the 'normal' s rotation to the floor. I had the same problem , but luckily Aldo Naletto provided the solution.

My question : http://answers.unity3d.com/questions/230216/why-am-i-getting-a-fruity-effect-from-my-raycast.html

Aldo's other post (with illustrations from the question's asker similar to yours) : http://answers.unity3d.com/questions/168097/orient-vehicle-to-ground-normal.html

So you have both js and C# versions, hope this helps a little =]

Comment
DavidDebnar

People who like this

1 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 AlucardJay · Apr 13, 2012 at 07:40 PM 1
Share

example build of my result : http://www.alucardj.net16.net/unityquestions/HoverBoard6.html

avatar image DavidDebnar · Apr 13, 2012 at 07:49 PM 0
Share

Thanks! Thats exactly what I've been looking for :)!!

avatar image

Answer by JayMHelpsU · Apr 13, 2012 at 07:24 PM

yes there is and its quite simple just get the floors rotation and make the cube as it rotation like so (Javascript)


var Cube : Transform;
var Floor : Transform;
function Update()
{
     Cube.rotation = Floor.rotation;
}
drag (in editor) the objects into their designated spots

Comment

People who like this

0 Show 5 · 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 DavidDebnar · Apr 13, 2012 at 07:30 PM 0
Share

Do you really think I couldn't have done this? That picture up there is just to show what I mean. I will have different curved floors in my game that won't work with this code.

avatar image JayMHelpsU · Apr 13, 2012 at 07:34 PM 0
Share

Im sorry it is quite hard to give help with the litte information provided, i wasnt believing you couldnt have done this , it was just a misunderstanding. Anyway a cube is a complex object to use because its flat sides. Two other options. You can make it go through the floor or you can have it with only various parts of a flat side touching the ground. Sorry for any inconvenience :)

avatar image Unicron · Apr 13, 2012 at 11:02 PM 0
Share

@dzebna, I'm also looking for a solution to this as this is something that I'm also trying to implement in my project. I have a round space station (2001: A Space Odyssey) and I need to have the player rotate to the floor angle as they walk around in it. Were you able to resolve it?

avatar image AlucardJay · Apr 14, 2012 at 02:25 AM 0
Share

check my answer =]

avatar image AlucardJay · Apr 14, 2012 at 03:51 AM 0
Share

e.g.

 var rayHit : RaycastHit;
 if (Physics.Raycast(transform.position, Vector3.down, rayHit, 5.0)) {
     transform.rotation = Quaternion.LookRotation(rayHit.normal);
 }

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

How to "clamp" a y rotation in unity? 0 Answers

Rotating cube steadily around world axis not working properly 0 Answers

The rotation of my objects when imported from blender are messed up 1 Answer

Rotation of Camera = Transform on the y-axis? 2 Answers

i need to rotate cube in z axis or x axis one direction at time 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