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 /
avatar image
0
Question by 82MiddleMan · Aug 27, 2015 at 12:21 PM · physics2d-platformerrigidbody2d2d-physics

Issues using physics for 2d platformer.

I have looked at many questions about the best way to control movement of a character in a 2d platform game and still can't find a decent answer. Also, none of them address the main problem I have which is that when I walk/run into a slope, not only does it let me go up very steep slopes, but it adds upwards force, and the character shoots up very far without jumping. This is the same if you just about make a platform when jumping to it and hit the edge.

I am using rigidbody2d.velocity = new Vector2 (move * maxSpeed, rb2d.velocity.y); for left and right movement, as suggested in a unity tutorial.

What is the best way to get round this, or, is there a better way to move the player?

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 82MiddleMan · Oct 16, 2015 at 02:44 AM

Thanks for the support unity. I ended up using this tutorial with a few tweeks if anyone else is wondering https://www.youtube.com/playlist?list=PLFt_AvWsXl0f0hqURlhyIoAabKPgRsqjz

Comment
Add comment · 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
0

Answer by GiyomuGames · Oct 16, 2015 at 02:44 AM

I don't have slopes on my game but I can understand why your character would become very fast: You are adding speed on the x axis regardless of the slope angle. Therefore it is trying to travel the same distance on the x axis as usual, but it needs to go faster as the actual distance is longer. The actual distance is "1 / cos(slope angle)" times the distance on a flat platform. From this formula you can see that if the slope angle is 0 then there is no change (cos(0) = 1), but the bigger the slope angle the greater the distance (and it explodes when the slope angle is 90 obviously as cos(90) = 0).

So you may want to do move * maxSpeed * Mathf.cos(slopeAngle) when your character in on a slope (or all the time if you consider that a flat platform is a slope of 0 degree).

Comment
Add comment · 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
0

Answer by GiyomuGames · Oct 16, 2015 at 01:41 AM

You should multiply move * maxSpeed by the cosinus of your slope angle to prevent your character from going faster on the slopes.

Indeed without the cosinus your character is trying to travel the same horizontal distance regardless of the slope angle. Therefore the steeper the slope the faster it has to go.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why doesn't Rigidbody.velocity.x = 0 in a collision? 1 Answer

2D Jump using "Rigidbody2D.AddForce" doesn't work. 1 Answer

How to check if my enemy hits the ground at a certain velocity then add explosive force. 1 Answer

Camera following Rigidbody jitter every few seconds with background 0 Answers

[2Dplatformer][Problem] When the player closes to the enemy, the enemy pass through the colliders 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