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 rodude123 · Apr 29, 2016 at 08:59 AM · 2danglejumping object

jumping at a degrees angle

I have this simple script which makes the character but I don't know how to make a the character move at an angle e.g. 45 degrees. I have already tried it but it is not working. I have tried changing the values but it doesn't work the way I want. It is meant to move upwards at a 45 degree angle but it doesn't.

 rigidbody2D.AddForce (new Vector2 (0f, jumpForce));

The code above is the original but I changed it to this and still doesn't work.

 rigidbody2D.AddForce (new Vector2 (5f, jumpForce));

It still doesn't work so how do I do it. I'm working in C#. Thanks in advance for any replies. Oh and I have already tried searching but nothing came up on this.

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

1 Reply

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

Answer by Eno-Khaon · Apr 29, 2016 at 09:32 AM

If you want your character to always jump at a 45 degree angle (from flat ground, at least), regardless of their current speed, you should be able to do it with something like:

 rigidbody2D.velocity += (Vector2.up * rigidbody2D.velocity.x);

Modifying the velocity directly rather than using AddForce, in this case, will ensure that mass is not a factor in the force added.

Comment
Add comment · Show 7 · 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 rodude123 · Apr 29, 2016 at 04:54 PM 0
Share

Will this work for Y axis because it is and endless 2D game in the Y axis. and would I change: rigidbody2D.velocity.x to this: -rigidbody2D.velocity.x for the other direction e.g. one for the right and one for the left. Thanks

avatar image Eno-Khaon rodude123 · Apr 29, 2016 at 05:12 PM 0
Share

Ah, right. $$anonymous$$y mistake on that one. You can just go with:

 $$anonymous$$athf.Abs(rigidbody2D.velocity.x)

and it'll always be a positive value.

 rigidbody2D.velocity += (Vector2.up * $$anonymous$$athf.Abs(rigidbody2D.velocity.x));

(Argh! Why do I keep writing things when I'm tired?)

avatar image rodude123 Eno-Khaon · Apr 29, 2016 at 05:53 PM 0
Share

Thanks for your help but it doesn't work. I will try to fix it my self again

Show more comments

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

67 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

Related Questions

How can I make an object stop all momentum and hold it's position in air? 1 Answer

2d Raycasting, trouble drawing rays at the correct angles 1 Answer

How to calculate angle between 2D objects and use the result? 0 Answers

Math to have a bullet penetrate stuff in 2D? 1 Answer

How can I limit the rotational speed of a gameObject tracking my mouse? 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