• 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
Question by Saxgu · Jan 02, 2018 at 04:48 AM · objectvelocityspeedpushconstant

Pushing and object up/down/left/right at constant speed

Hi, I'm making a 2D game and my character moves at constant speed in any direction using WASD. I want my character to be able to push crates, and when it does so I want it to move at a lower speed and the create must move at the same speed. My problem is the following:

Created a Boolean variable that indicates whenever the characters collider is in contact with the Crates collider and this in turn slows the players speed so that it pushes the crate at a lower speed. I reset the speed of the crate to 0 whenever the character and the crate get separated so that it stays in place.

However when pushing for "long" distances the crate somehow manages to get out of the characters reach (just by small distance) which make the player restore it's usual speed and causes the crate to stop, but then they eventually both get into contact again and the character moves again at a reduced speed along with the crate. This creates an undesired effect of the player moving not at a constant speed, and the crate suddenly stoping for an instant an then moving again, the bool variable turns OFF and ON even if the Player never stopped pressing the W to push it up for example.

Is there any way to make sure the crate never gets out of range so that the player keeps moving at a lower constant speed? I wish to keep the effect that whenever the Player stops pushing the crate (when the WASD keys are lifted) moves still a little bit farther so that that it stays out of reach and the player can move freely without accidentally pushing it again inmediately.

By the way both the character have a rigidbody2D with the gravity scale set to 0. And they have 2d Colliders as well. The characters rigidbody2d is set to never sleep due to toher functionalities.

Thanks for your help.

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

74 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My moving object decelerates when almost reaching a next point in the bezier curve,My gameobject decelerates when reaching a next point 0 Answers

Why do my objects keep changing speed? 1 Answer

Can an object to transfer to another as it increases your speed? 1 Answer

how to keep speed canstant in flappy bird? 2 Answers

How should I move an object that parents on collision? 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