• 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 Bubj · Sep 23, 2014 at 06:16 PM · rigidbody2d

Add speed to a 2d object regardless of direction.

I am trying to create a ball that gains speed whenever it bounces off a an object. I tried using rigidbody2D.AddForce and rigidbody2D.velocity but these are directional and i would have to know the direction the ball is facing in order to add a speed in the right direction. I came into a problem where if the ball was moving a left and it hit a collider and I added a force to its x direction that was positive it would slow down or at times equal out to 0 and the ball would just go straight up or down. Knowing which direction the ball is facing to add force or velocity in the right negative or positive value is possible but seems like a unnecessary work around to a simple solution I just cant figure out and dose not seem like a optimal solution.

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 robertbu · Sep 23, 2014 at 06:17 PM 0
Share

I'm away from my desk and cannot test it, but I'd start by multiplying the rigidbody2D.velocity by some factor on the OnCollisionExit2D() call...or maybe the frame after the call.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Freaking-Pingo · Sep 23, 2014 at 06:33 PM

Why is it such as hassle obtaining the direction of the ball. rigidbody2D.velocity contains the direction of your ball, within its x, y, z components? If you only are interested in manipulating the speed by some factor, you could do something like this:

 rigidbody2D.velocity *= someFactor;

This will increase the speed of the ball, in its current direction.

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 Bubj · Oct 20, 2014 at 09:40 PM 0
Share

Just went for finding the direction of the ball. Dont know why I thought it would be taxing or inefficient for a mobile phone.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rigidbody2D freezes 0 Answers

Animations don't Update 1 Answer

Make Enemy movement "superior" to player movement. 1 Answer

[Networking] Sync child rigidbodies 0 Answers

Unity 2d Physics Collision Jumping / Glitching 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