• 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 Dgrohl91 · Apr 08, 2016 at 04:03 PM · rigidbodyenemypushpushback

Push back an enemy on trigger

I have two gameobjects, one of them is my "hero" an the other one the enemy with a NavMesh, I've managed to make the health system without problems but know when the sword collides with the enemy it seems that the rigidbody is not working or something because I've tried a couple of solutions that I've found on Internet but nothing seem to work. I want the enemy to be pushed once the sword collides with it. I've tried this:

 public void takeDamage() { 
   // revert rigidbody velocity:
   rigidbody.velocity *= -1;
 }

Another code

 float distance = 25.0f;
                 if (player.position.x < enemyPosition.position.x) {
                 Vector3 new_position = new Vector3 (enemyPosition.position.x + distance, enemyPosition.position.y, enemyPosition.position.z);
                 rb.position = new_position;
                 }

Thanks

Comment
Add comment · Show 1
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 Fredex8 · Apr 08, 2016 at 05:41 PM 0
Share

Have a look at AddForce.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

59 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

Related Questions

Push an object behind itself with No RigidBody 0 Answers

navmeshagent and rigidbody question 0 Answers

Unity physics problem when try push big rigidbody objects 0 Answers

How do I prevent my player from pushing a jumping enemy off screen? 0 Answers

Rigidbody.AddForce effect on Character Controller without rigidbody 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges