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 Treven · Sep 26, 2015 at 05:55 PM · movement2d gamerigidbody2dgravityjumping

Why does this piece of code work with gravity and this one dosent

Hey i working with this code for movement it works the way i want to except for jumping. My player, when he jumps goes through an instant jump upwards and a slow decent. I have found the problem in my basic movement code but i don't get why its doing what it does. The commented out piece works with gravity but the other one dosen't. can you help explain why this is and give me a solution if possible?

     moveVelocity = moveSpeed * (Input.GetAxisRaw ("Horizontal"));
             //myRigidbody2D.velocity = new Vector2 (moveVelocity * transform.right.x, myRigidbody2D.velocity.y);
             myRigidbody2D.velocity = transform.right * moveVelocity;

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Rostam24 · Sep 26, 2015 at 08:24 PM

When I changed every rigidbody in my game to rigidbody2d, I had the same problem. Eventually, I ended up using rigidbody2d.AddForce for everything. Setting velocity or moveposition in one place would overwrite what I did in other places. I have no idea why that happened (I'm still pretty new to Unity), but using addforce was the solution for me.

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 Treven · Sep 26, 2015 at 10:46 PM 0
Share

um that dosent work because add force will continue to speed up over time

avatar image Rostam24 Treven · Sep 26, 2015 at 10:54 PM 0
Share

You'll need to set some kind of maxspeed and check for that before doing addforce. I just shared my code in another answer, you could take a look at it for ideas: http://answers.unity3d.com/questions/1072298/simulating-fighter-jet-physics-with-addforce.html

avatar image Treven Rostam24 · Oct 06, 2015 at 04:10 AM 0
Share

that did not work

avatar image
0

Answer by cjdev · Sep 27, 2015 at 06:19 AM

In the first commented line you are moving in both the x-axis, by 'moveVelocity' units to the right, and in the y-axis, by your Rigidbody y-velocity (gravity).

In the second line you are moving only in the x-axis to the right at a speed of 'moveVelocity' units. There's no y-axis movement involved so you aren't going to see any effect from gravity. Try adding in the Rigidbody's y-velocity to the second one to account for gravity again.

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 Treven · Oct 06, 2015 at 01:40 AM 0
Share

I put in myRigidbody2D.velocity = transform.right moveVelocity myRigidbody2D.velocity.y; and my character didnt move unless i jumped and when i did it went crazy

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I make a character Lunge? 2 Answers

Character drops from air when using velocity Jump and transform.translate direction after releasing W key 0 Answers

Can someone help me with this Rigidbody2D bug? 1 Answer

I want to move the player once while he is jumping 1 Answer

Simple Rigidbody2D movement and jump 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