• 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 akromm · May 02, 2017 at 05:55 AM · collidersphysics2dmomentum

Transfer momentum

I'm trying to make a simple 2D "Sonic the Hedgehog 2" type game.

Currently I have:

ball: has a CircleCollider2D (not a trigger), and a Rigidbody2D. The rigid body is set as Dynamic and uses Continuous collision detection.

To move the ball I use Rigidbody2D.AddForce() to add a force in the direction I want the ball to go.

Platform: has a 'EdgeCollider2D` (static) but no rigid body.

The platform is flat and at the end has an upwards curve that gradually goes from 0° (horizontal) to 90° (vertical). What I'm trying to achieve is have the ball move horizontally across the flat platform then when it reaches the part that starts curving upwards have the ball follow the curve.

The issue is that if the ball moves too slowly it can't make it up the curve. If it moves faster it ends up either: going through the curved platform; or just stopping dead half way up with very jerky movement.

I imagine the issue with the ball stopping is that the momentum of the ball is not being transferred properly to follow the curve of the platform. To try to fix this I have the code written such that it takes the normal of the collider contact point and and use that to rotate the ball's rigid body such that the up vector matches the normal of the contact point. Thus when adding a force it is now parallel to the collider surface. I also take the rigid body velocity and update it to be parallel to the ground surface using the same idea. This however doesn't seem to fix/update the momentum of the ball to follow along the path, and I still have issues with the ball going through the platform collider when moving moderately fast (not very fast).

How do I update the momentum of a rigidbody to follow a curve?

Comment
Add comment · Show 1
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 toddisarockstar · May 03, 2017 at 06:01 AM 0
Share

using a charactercontroller ins$$anonymous$$d of other colliders gives you some extra related settings. if that doesnt help your situation you could consider using Oncollision stay to see if it is grounded to make adjustments. maybe even grab and ajust the velocity direction to the angle of the ground it is touching

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by shellash · May 03, 2017 at 07:15 AM

Hello!

Have you tried using Rigidbody.velocity instead of AddForce?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

elastic collision simulation loses 400 kgm/s momentum in a few hours 1 Answer

A tricky problem with Particle Collisions 0 Answers

colliders vs raycast vs physics.overlap? 0 Answers

[SOLVED] Physics2D OverlapCircle 2 Answers

Colliders 2d apparently touch each other even if they should not. 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges