Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by slehmann101 · Mar 04, 2014 at 01:41 AM · unity 2daddforceforcedegrees

Add a force at an angle

How do I add a force at specific angle to an object? Currently I am trying to do the following:

 rigidbody2D.AddForce(new Vector2(1,Mathf.Cos(angle))*force);

where angle would represent the angle at which the force is added, so if i wanted a force straight up then angle would be 90. However this does not seem to work, and I would like to know what the correct way to accomplish this is. I am using C# and unity 2D

Comment
Add comment · Show 2
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 highpockets · Mar 04, 2014 at 04:03 AM 0
Share

How are you getting the angle that you want to apply??

avatar image slehmann101 · Mar 04, 2014 at 04:16 AM 0
Share

angle is just a public float which i am setting in the inspector

1 Reply

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

Answer by robertbu · Mar 04, 2014 at 05:20 AM

How about this:

  Vector3 dir = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;
  rigidbody2D.AddForce(dir*force);

The angle starts on the right and goes counter-clockwise.

Comment
Add comment · Show 3 · 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 slehmann101 · Mar 07, 2014 at 05:03 AM 0
Share

I get the error

UnityEngine.$$anonymous$$athf' does not contain a definition for `AngleAxis'

avatar image robertbu · Mar 07, 2014 at 05:14 AM 0
Share

Sorry. It is Quaternion.AngleAxis(). Code sample fixed.

avatar image slehmann101 · Mar 07, 2014 at 11:18 PM 0
Share

thank you

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

25 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

Related Questions

Use Rigidbody2D's Drag to slow down flying character 1 Answer

Ball Rotating Help 0 Answers

Use force instead of transform.position 1 Answer

Separating direction from force w/ rigidbody.AddForce 1 Answer

Adding force to rigidbody2d to slide 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