Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by S4breK4t · Aug 18, 2015 at 12:34 PM · 2drotationplatformerslope

Gradually rotate to slope angle

In my platformer game, I want my character to rotate to the angle of the slope they are standing on. However, to make this work properly I dont want them to suddenly rotate to the angle upon making contact with the slope else it will look horrible and undoubtedly throw up a tonne of collision issues. Instead, I want them to gradually rotate as shown in the images, so that they will rotate as much as they can each frame until they cant any further due to a collision with the back corner. How would I do this, and how would I change the pivot point of the character to the front bottom corner in order to make this work? Code in C#. Thanks.

alt text alt text

slopewant.png (19.2 kB)
slopewant2.png (29.2 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by stepan-stulov · Aug 18, 2015 at 01:49 PM

You don't have to have visual and collision representations of the level be the same. What you can always do is a sharp corner in the visual representation and a smooth round (or at least a polygon with more steps to approximate roundness) collider int the collision representation. alt text


graphics-colliders.png (32.6 kB)
Comment
Add comment · 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 S4breK4t · Aug 18, 2015 at 03:37 PM 0
Share

Im not doing it for aesthetics, its because instantly rotating it to slope angle will put it through the floor if its at the bottom of a slope, which completely messes it up

avatar image S4breK4t · Aug 18, 2015 at 06:31 PM 0
Share

This is exactly my issue:

alt text

avatar image
0

Answer by Owen-Reynolds · Aug 18, 2015 at 02:01 PM

Do you really need the precise placement shown in the pictures to the right? Most games let there be a little overlap -- your feet are in the grass, or bushes, or soft dirt ... . If you need that picture it seems like more of a trig problem (it won't slowly rotate -- it will snap to the computed math rotation as it moves, which will slowly change.)

But most games, when you hit the slope, will slowly spin, will put your back foot through the ground, but you've probably moved by then anyway. You can look up finding the normal and gradual rotations.

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 S4breK4t · Aug 18, 2015 at 02:23 PM 0
Share

The reason I decided to do it how I said was because having a snap-to rotation put the character into the floor as soon as they touched the bottom of the slope, causing lots of collision problems. The main reason Im having trouble with this is because I dont know what to do when it comes to the base and top of a slope.

avatar image Owen-Reynolds · Aug 18, 2015 at 04:06 PM 0
Share

But, what part do you need and what part is merely "I feel like this might work?"

When the player is fully on a sloped ramp, must exactly match the slope? And then just do whatever works when two slopes meet? Is this physics-based, or hand-moved? Physics-based give you the option for spring-joints to fix the problem, but they tend to give you 90% of what you wanted.

It feels like it's still at the design problem stage.

avatar image S4breK4t · Aug 18, 2015 at 04:24 PM 0
Share

The other option is just rotating the graphics ins$$anonymous$$d of the actual player. However, something that I do want is for the player to jump at the angle of the normal of the slope ins$$anonymous$$d of straight up, and I thought this was easiest to implement if the player was already rotated to the slope so that the jump direction would just be transform.up

avatar image S4breK4t · Aug 18, 2015 at 06:32 PM 0
Share

This is exactly my issue:

alt text

avatar image
0

Answer by Saddamjit_Singh · Sep 04, 2017 at 05:45 AM

Hi ,

Use the script below -

  RaycastHit hit;
  Quaternion rot;
   public  int smooth;
 
 void Update()
         {
             Ray ray = new Ray(transform.position, -transform.up);
             if (Physics.Raycast(ray, out hit))
             {
                 rot = Quaternion.FromToRotation(transform.up, hit.normal) * Quaternion.Euler(0, transform.rotation.y, transform.rotation.z);
                 transform.rotation = Quaternion.Lerp(transform.rotation, rot, Time.deltaTime * smooth);
             }
         }
 
Comment
Add comment · Show 1 · 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 Owen-Reynolds · Sep 05, 2017 at 01:00 AM 0
Share

For advice for just one person, try to check the date. This Q is two years old. Almost no one cleans up a Q (for example, writing that they found an answer.) Any Q more than about a month old, they're done with it.

It is O$$anonymous$$, even encouraged, to add better answers for "the internet" to old Qs. But do a Search first. What you wrote here is already a common, easy-to-find answer. There's also another easy-to-find answer using several ground contacts (which is what the original poster seemed to want.)

If it's a fresh question with an easy-to-find answer here in UA, it's considered polite to just make a link, ins$$anonymous$$d of a cut/paste.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I want to make my camera follow the player ONLY when the player is on solid ground [2D] 0 Answers

Infinite collider 2 Answers

Rotate 2D pivot so that gun points at target. 0 Answers

how to lean an object smothly towards its moving direction by its velocity? 1 Answer

Raycast Reflection 2D 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