Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Ownedbycow · Jan 02, 2015 at 05:53 PM · movementrigidbodytransformvelocity2d platformer

Best way to move a character in a 2d platformer?

transform.translate causes a steady movement but causes the player to jitter.

rigidbody2D.velocity=Vector3.right* -4; makes the character move steady but makes gravity work weird. If you are running then try to jump, it barely works. But if you jump then move, you can glide for a long distance

rigidbody2D.AddForce (Vector3.right * 4.5f); starts off really slow but within a few seconds is moving too fast too control.

What is a good way to get my character to move properly without the negative effects of the three examples that I mentioned? If more info is needed, I will try to provide it.

Plus if I use transform.translate, setting timeScale to 0 doesn't work right. As anything using transform.translate still moves.

Oh I think I have an idea, I just don't know how I would do it. Can I set a limit/maximum to the force applied if I used the addforce method?

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
2

Answer by Anxo · Jan 02, 2015 at 06:07 PM

transform.translate does not cause jitter, the jitter is caused by what and how you are feeding the method. All 3 of these are fine, it just depends on what kind of controls you wish to accomplish. velocity is the easiest and most direct way to control your character while still respecting collisions and physics, the problems you are running into with gravity is just due to how you are applying it.

For instance, cushion your moving velocity in a "isGrounded" bool. That way you control the velocity while running but let physics take over once you jump.

run, velocity is in control, hit jump, isGrounded = false, physics takes over and controls the character till isGrounded is true again.

But just do this tutorial and you will get the idea. http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers

Comment
Add comment · Show 2 · 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 Ownedbycow · Jan 02, 2015 at 06:16 PM 0
Share

I was using a isGrounded bool already to stop the player from jumping while in the air, but with using the method that you mentioned would I be able to allow to player to somehow change directions in the air? I want the player to be able to correct themselves slightly if they time their jump was timed incorrectly. Plus I just tried it and it works fine only if I left off the movement key first. Should this mean that I should put jumping over movement in the script? Going to watch the tutorial as soon as it loads. Slow internet and that's a long tutorial ^_^ Thanks for the reply btw

I just thought about it for the movement in the air, I could just do an if check to see if they are grounded then if not, they can move, just at a slower rate. I think thats right anyways

avatar image Anxo · Jan 02, 2015 at 07:10 PM 0
Share

yes, if you wish to manipulate the trajectory of someone in the air you can just ad to the velocity.

 rigidbody2D.velocity = rigidbody2D.velocity + airControl;  // air control being a vector 2 

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

Calculate Local Velocity of a body at a specific point 0 Answers

Stop A player Turning at Specific Point. 1 Answer

How to make a gamebject wiggle slowly as it moves forward ? 1 Answer

Restrict a Players Movement Up a Slope 1 Answer

Rigidbody movement conflict? 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