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
1
Question by SPIGS · Jan 18, 2014 at 01:39 AM · movementtopdownrigidbody 2d

Whats the best way to move a 2d rigidbody?

My 2d character has a rigidbody attached to it. What is the best way to move it? Should I modify the transform, use AddForce, or set a velocity? Answers appreciated.

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
-1

Answer by YoungDeveloper · Jan 19, 2014 at 07:19 PM

Changing transform would be the most easiest and best way in my opinion. And instead of gravity you could shoot ray down and fake the falling and jumping effect, at least it would be more optimized solution.

Comment
Add comment · Show 4 · 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 SPIGS · Jan 19, 2014 at 07:28 PM 0
Share

I forgot to mention my character moves in 8 directions like in Legend of Zelda. There is no gravity in my game. Wouldn't modifying the transform cause errors in the collision? Like hitting a wall?

avatar image YoungDeveloper · Jan 19, 2014 at 07:48 PM 0
Share

There should be a collider around walls, houses and other objects. On mouse click, cast a ray, and move player only if hit.collider.gameObject.tag == "Terrain". Or are you moving your character with keyboard arrows only ?

avatar image SPIGS · Jan 19, 2014 at 08:09 PM 0
Share

Yes. arrows only

avatar image YoungDeveloper · Jan 19, 2014 at 08:20 PM 0
Share

You would still need some kind or barriers, which wouldn't not let player go past certain area. But it really depends on how your game will be made.

If you don't $$anonymous$$d player "sliding" against the wall if he hits a collider by you continue walking then simple colliders would be the easiest solution.

But if the game will be "cubed" environment only, like most classic 2 or 2.5D games, then raycast to each direction (4) could be a simple but effective solution.

avatar image
0

Answer by Vardan Meliksetyan · Jan 19, 2014 at 07:36 PM

For pool game I use AddForce() function

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html

I used AddForceAtPosition()

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForceAtPosition.html

it work normal , it was 3D game , I use this in 2D it work good!

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

20 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

Related Questions

Enemy Movement Help 3 Answers

Top down 2d movement without being affected by rotation 2 Answers

Move camera and player OR move objects? 1 Answer

Help with topdown movement in Unity2d? 1 Answer

How do I detect when my player is moving in unity 2d? 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