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 /
  • Help Room /
avatar image
0
Question by killerKeks26601 · Mar 05, 2021 at 11:05 AM · 2d-platformerrotations

(2D) face movement direction

Hello, I am very new to Unity, and im having a lot of trouble with rotations. I managed to align my player to rotate accordingly alongside slopes(tho i still have to find a way to limit that effect to stop him from going upside down) but now im having trouble with flipping my character to face the movement direction. I already managed to do that in an earlier script but that method seems to cause some trouble now as my player either doesnt flip at all or only for a split second. I am guessing that my new rotation script for handling slopes and my flipping script are interfering with each other.

 void FixedUpdate()
 
 {
         myCollider.Cast(-Vector3.up,contactFilter,contactPoints ,myCollider.bounds.extents.y + 0.1f, true);
         for(int i = 0; i < contactPoints.Length; i++)
         {
             var angle = Mathf.Atan2(contactPoints[i].normal.x,contactPoints[i].normal.y) * Mathf.Rad2Deg;
             transform.rotation = Quaternion.AngleAxis(angle, -Vector3.forward);
         }
         if(isGrounded == false)
         {
             Vector3 eulerRotation = transform.rotation.eulerAngles;
             transform.rotation = Quaternion.Euler(eulerRotation.x, eulerRotation.y, 0);
         }
         if((xMov < 0 && facingRight) || (xMov > 0 && !facingRight))
         {
             facingRight = !facingRight;
             transform.Rotate(new Vector3(0, 180, 0));
         }
         Raycast = Physics2D.Raycast(transform.position, -Vector2.up, 0.5f);
         if(Raycast.collider != null)
         {
             isGrounded = true;
         }
         else if(Raycast.collider == null)
         {
             isGrounded = false;
         }
         if(jumpInput == true && isGrounded)
         {
             rb.AddForce(new Vector2(0, inventory.CurrentPlayerClass.jumpForce), ForceMode2D.Impulse);
             jumpInput = false;
         }
 
         rb.AddForce(new Vector2(xMov * inventory.CurrentPlayerClass.movementSpeed, 0), ForceMode2D.Force);
 
     }


If you have any comments or any advice on any of the code especially on the problem i stated would be awesome. I started coding like 2-3 months ago and want to learn as much as i can.

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

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

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

Kinematic and Dynamic boides 0 Answers

Problems with tilemaps of Unity 2d-extras 1 Answer

hi i want to add a slid and wall jump to my script with animation, i am lost ^^ 0 Answers

Changing game from PC to HTML5 creates errors 0 Answers

Stationary Enemies from Tilemap 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