Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by Impstar · Dec 09, 2016 at 10:07 PM · unity 5movementenemy

Running into enemies moves them; how to stop this?

I'm creating a 2D Platformer with enemies. I want to make it so when you run into an enemy they don't move. At the moment, if the player is willing to take collision damage, they can just push enemies out of the way.

The enemies need to be able to move themselves (like pacing) however, so I can't just set it so they can't move at all.

Ideas? I can get more specific and post code if it's helpful as well.

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
0
Best Answer

Answer by RobAnthem · Dec 09, 2016 at 10:18 PM

Remove the rigidbody from your enemy. Or make a script that detects the player collision and overrides it.

Comment
Add comment · Show 3 · 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 Impstar · Dec 09, 2016 at 10:22 PM 0
Share

Would that stop physics from affecting the enemies if I did that? I still want them to hit walls and the player, I just don't want the player to be able to push them. And obviously I still want gravity to affect them.

I'm pretty new, so I don't always understand all the repercussions of everything.

avatar image RobAnthem · Dec 10, 2016 at 02:04 AM 0
Share

Gravity can be applied without a Rigidbody, and colliders deter$$anonymous$$e collision, essentially unless your Rigidbody physics actually utilize physics and aren't an animation, then it isn't necessary. However, Rigidbodies do provide some nice aspects, and as such I'd still recommend finding a way to use them. $$anonymous$$y best suggestion would be to do this:

 void OnCollisionEnter(Collision collision)
     {
         Collider playerCollider = GetComponent<playerScript>().playerCollider;
         if (collision.collider == playerCollider)
         {
             rigidbody.is$$anonymous$$inematic = true;
             rigidbody.velocity = Vector3.zero;
             hitByPlayer = true;
         }
     }
 void Update()
     {
         if (rigidbody.is$$anonymous$$inematic == true)
         {
             rigidbody.is$$anonymous$$inematic = false;
         }
     }
avatar image Impstar · Dec 10, 2016 at 03:05 AM 0
Share

Thanks, I'll give that a shot. I ended up turning up the mass on their rigid bodies so they can't be moved, but your way seems more elegant.

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

135 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

Related Questions

Object movement algorithm 0 Answers

I'm making a zero gravity VR game and need help with the movement. Could someone help? 0 Answers

how to make forward relative to the view of the camera 0 Answers

How to stop movement script on void start and resume after. 0 Answers

make something move when not looking at it 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