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 ypsilon · Apr 02, 2014 at 12:13 AM · rigidbodycolliderpush

Rigid bodies not to push each other?

I'm starting a beat'em up game. I've implemented the player with a rigidBody and several colliders, and was thinking about doing the same for the enemies. The reason for this is that I want Unity to handle the physics for me. The way I'm moving my character is modifying the transform's velocity.

Now my problem: if I add for example a cube (representing an enemy), with its corresponding rigid body and collider, and I make my character go walk against it, the cube will then be pushed by the player. Now, I don't want this to happen, since I don't want characters in general to be able to push each other.

My question: is there any way of avoiding this? I might have to change my whole approach to the implementation in case this couldn't be done.

Thanks!

Comment
Add comment · Show 2
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 getyour411 · Apr 02, 2014 at 12:25 AM 0
Share

If you have rigidbodies (not is$$anonymous$$inestmatic) and actual Colliders (not isTrigger) than no, you'll get collisions. You can look at both of those options and physics interactions to tweak what you want to happen, or you can clarify what it is you DO want to happen.

avatar image ypsilon · Apr 03, 2014 at 08:23 AM 0
Share

I think I'll have to do that. I'll have to code my own physics I guess.

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by ypsilon · Apr 08, 2014 at 04:16 PM

This is not an actual solution to this problem, but it is how I've ended up doing it:

  1. I have just disabled the collisions between the "Player" and "Enemy" layers, letting the different characters in the game pass through each other (if you check out other classic beat'em up titles like Turtles in Time for the SNES, you'll find out that this is how they did it)

  2. Each character now has a rigid body and a normal collider. This collider is to check for collisions with other non-character elements, like the ground.

  3. Each character has one or more trigger colliders to detect colliders coming from the next point:

  4. Each fighting movement has a collider (for example attached to the fist in the case of punching), that will be detected by the trigger collider attached to the character being attacked.

This is the best approach that I've found for my case.

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 KaffeSumpen · Oct 22, 2016 at 10:26 AM 0
Share

This is a great sollution, was trying to find a way achieve just this. For clarification for anyone finding this answer, to disable collision between layers you make changes in the Layer Collision $$anonymous$$atrix (the thing that looks like a triangle of checkboxes) in the appropriate Physics $$anonymous$$anager.

For 3D collisions check here https://docs.unity3d.com/$$anonymous$$anual/class-Physics$$anonymous$$anager.html

For 2D collisions check here: https://docs.unity3d.com/$$anonymous$$anual/class-Physics2D$$anonymous$$anager.html

avatar image VanHai · Mar 23, 2018 at 02:59 AM 0
Share

Good solusion for Fighting games genre

avatar image
1

Answer by MileSplit · Apr 02, 2014 at 03:08 AM

I had this same problem, play around with the weight values of the rigidbody for enemies and players. For example increasing the weight of an enemy should not allow it to be pushed.

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 ypsilon · Apr 02, 2014 at 10:16 PM 0
Share

Effectively, if I increase the enemy's mass I'm not able to push it with the player. But the enemy would be able to push my player then... So I'm at the starting point

avatar image
1

Answer by arkariarn · Apr 02, 2014 at 10:57 PM

I would set the collider of the enemy to a trigger and handle his movement by script. But this way he will go through everything, even walls, so maybe a simple raycast2d to check if there is a wall in a direction (you can do this by using a layermask)can do the trick:

  if(Physics2D.Raycast(transform.position, vector2.right + transform.position, 1, 1 << 8)){
 //stop moving
     }

so this would check if there is a wall to the right of the enemy at a distance of 1, given that you have made a new layer wall on the 8th layer.

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 ypsilon · Apr 03, 2014 at 08:41 AM 0
Share

It's a good point, although it doesn't seem consistent to me to have the physics of the player be handled by unity and the ones from the enemies to be handled manually.

avatar image
0

Answer by Cornelis-de-Jager · Mar 23, 2018 at 04:06 AM

All the objects in the game you can make Kenimatic . As for the players, lock their X and Z position.

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

25 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

Related Questions

Detecting when Player stoped to push a rigidbody? 3 Answers

Making Colliders/Triggers or Rigidbodies move a Character Controller 5 Answers

How to make certain rigidbody2d's not able to push other rigidbody2d's? 2 Answers

How to prevent a rigidbody from pushing other rigidbodies? 1 Answer

C#: "Pushable" obstacles for a puzzle 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