• 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 Fixe96 · Mar 04, 2017 at 12:50 PM · unity 52d game2d-physicstop down

[2D] Slide object after collision

Hello community!

I am currently working on a top down 2D game and I got a little problem.

I want to make an object slide AFTER a collision. So that the player changes the direction (with the "W-A-S-D" keys), but the object which was hit before slides a bit in the previous direction.

Here is my code so far, but it doesn't work: (for example, when the player pushed the object to the right):

 private void OnCollisionExit(Collision collision) 
 {
     collision.transform.Translate (Vector3.right*10);
 }

I hope you understand what I want to do and thanks in advance!

EDIT: It is a top down game, so there is no gravity.

EDIT2: I added a few images.

alt text

alt text

direction-change.jpg (150.4 kB)
after-change.jpg (93.3 kB)
Comment
Add comment · Show 7
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 $$anonymous$$ · Mar 04, 2017 at 12:58 PM 0
Share

"So that the player changes the direction, but the object which was hit before slides a bit after that direction change because that object doesn't change their direction."

Could you rephrase this? i dont think i understand it fully..

avatar image Fixe96 $$anonymous$$ · Mar 04, 2017 at 01:01 PM 0
Share

I updated it.

avatar image $$anonymous$$ Fixe96 · Mar 04, 2017 at 01:19 PM 0
Share

Ohhhhh do you mean that the phyisics dont fit into the grid properly???? So what you want is that that object fits into the grid perfectly

Show more comments
Show more comments
avatar image Fixe96 $$anonymous$$ · Mar 04, 2017 at 01:35 PM 0
Share

The method is just an example. Is there a better way to slide an object ?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Mar 04, 2017 at 01:49 PM

Honestly, the best way I see moving this object is through the physics supplied in the engine... make the mass of the Player larger than the box, and when the character moves and collides with the object.. the object will slide via being pushed by the character...

No need for to re-invent the wheel heres a previous question that has created a movement script for a top down style game: http://answers.unity3d.com/questions/883081/2d-top-down-character-controller.html

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

Answer by xm4str33 · May 06 at 10:13 AM

This works for 3D games

  1. Go to your player's rigid body > increase the Drag number

  2. Go to your player's rigid body > Constraints > Freeze Rotation on XYZ and Freeze Position on Y

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

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

[2D] Make player push object 1 Answer

Player can only jump once!? 0 Answers

Unity 2D: Interpolate object collision stuck 1 Answer

2D Android Game Rapid Jumping Problem,Unity 2018.2.9f1 Android 2d Speed Jumping 0 Answers

top down 2d shooter direction of enemies 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