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 /
  • Help Room /
avatar image
0
Question by Snailien · Apr 26, 2016 at 01:29 PM · physicsgravityjumpaddforce

Confused about how AddForce works

Hey there, guys! I wanted to check out something with the community, because I can't seem to get why add force works the way it does (I assume it has something with gravity, but it will be way easier for me if I understand why).
Anyways, here is the problem- I try to make a 2D platformer, and for jumping, I use a simple one line of code- if jump button is pressed, the code adds force equals to Vector2.up * jump velocity. And it works like a charm. However, if I substitute Vector2.up with Vector2.right, it does nothing, or if the velocity is some insane number like 42000, it teleports the player few pixel to the right.
I did solve this, in the end, because I wanted this for my dash script, by implementing a timer and a bool, so I add horizontal force over some amount of time (the timer parameter), and resetting it after it reaches zero (plus cooldown, but that's not really relevant to the question).

So, actually, I'm completely confused about why is this happening? Why the simple one line of code for adding force on the Y axis gives a smooth jump, and I need all the timers, bools and ten times more complex script for achieving the same on X axis? I assume it has something to do with gravity, but I'm really confused as to why exactly this is happening.

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 fafase · Apr 26, 2016 at 02:00 PM 0
Share

You should show the line of code. Edit your post to add it. Without it, we can only assume what you are doing wrong.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Firedan1176 · Apr 26, 2016 at 03:20 PM

For the jump, I think it would be more beneficial if you are also including ForceMode.Impulse in your AddForce call. However, I do not understand what is causing the problem for your x-axis movement. Is it possible you are moving away from the camera in the Z axis (in 2D) instead of the X axis? Other than that, I do not know what could be causing the problem without seeing your code AND your scene.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rigidbody doesn't seem to apply gravity 1 Answer

How to make GameObject fall with the same gravity while using AddForce() 1 Answer

How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers

How to change physics properly? 0 Answers

Character not jumping smoothly using CharacterController 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