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
0
Question by Condore · Oct 29, 2012 at 11:34 PM · enemynavmeshnavigationcombatknockback

Knockback using Navmesh

Hey guys!

Another question from me,

I'm trying to simulate knocking back an enemy when they are hit by the "box collider" I have attached to the players weapon. I was just wondering how I could push the enemy backwards, away from the player using a Navmesh command/function rather than using Addforce, which is what I have implemented currently. As it throw my enemy's off of the navmesh and they slide around.

Any and all help is appreciated!

Thanks!

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

Answer by sparkzbarca · Oct 30, 2012 at 07:01 AM

set the destination equal to a point x distance along the vector goes from player to ai.

direction = ai.position - player.position;

distance = 1; destination = direction * distance

this would make the destination 1 unit (a unit in unity is 1 meter) or approx 3 feet away from the player in the direction of the ai character.

Assuming the players are scaled right (a normal sized human is approx 2 units or 6 feet in height) and the ai is standing very close to the player the ai would move to a position just under 3 feet away. Thats one way to do it though it kinda makes the AI run there if thats the animation its under. You'd need a knockback animation that shows him going through the air or however you want him to look when knocked back and orient it with the front towards the player so that as he moves toward the destination he still faces you and APPEARS to be knocked back, if you bump up the speed to fast and give it the right animation he'll move quickly backwards while facing you and basically he'll be knocked back.

You said he was knocked out of the navmesh why exactly? does the nav mesh not fully encompass your terrain? how is he getting knocked off it?

Comment
Add comment · Show 6 · 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 Condore · Oct 30, 2012 at 08:46 PM 0
Share

They seem to be getting knocked off of the Navmesh, because we're currently detecting our collision, by using a rigidbody and a capsule collider and we're using Addforce on it, in order to knock our enemies around. For some reason, it's causing our enemies to slide around sometimes when we attack them and it's the only explanation I can think of, for why they won't stop sliding after being hit.

avatar image sparkzbarca · Oct 30, 2012 at 09:37 PM 1
Share

view navmesh and pause after knockback to see if they leave the navmesh. still sliding might mean the force isn't at some point being removed, like they have a low friction coeffiecent. $$anonymous$$aybe they slide so much because they are in fact slippery? Unfortunately I do not own unity Pro so i cannot help you with Nav$$anonymous$$esh that much.

Do they still slide when you create an empty terrain completely covered in navmesh? If so you can rule out bla$$anonymous$$g the navmesh

If they dont your correct its the navmesh and you'll need to restrict movement to along the navmesh

You said SO$$anonymous$$ETI$$anonymous$$ES they slide. I assume that means sometimes they dont. debug log the force on them. maybe its being continually added sometimes.

avatar image Condore · Nov 07, 2012 at 03:00 AM 0
Share

Thank you. It's been fixed based on what we discussed the problem was in fact the nav mesh, but it was because they were set as kinematic rigidbodies before and they were being set to false.

We went back into our collision code and made sure our code was re-enabling the nav mesh agent and making them kinematic once again, so they stopped sliding around.

avatar image sparkzbarca · Nov 07, 2012 at 03:23 AM 0
Share

You said you were using addforce but using $$anonymous$$inematic rigidbodies?

Thats wierd how is that working?

$$anonymous$$inematic means it doesnt use the physics engine. I guess are you disabling kinematic, knocking them back, then making them kinematic again to remove the force?

just to note you could use a slerp move to avoid changing there kinematic status.

$$anonymous$$inematic objects are nice except that they only collide when placed within the fixed update.

A charactercontroller is probably more of what you want here since its probably a traditional AI.

Well whatever works for you. :)

avatar image Condore · Nov 07, 2012 at 06:34 PM 0
Share

Yeah that's exactly what we're doing. We're also disabling the Nav $$anonymous$$esh agent before we set their kinematic value to false. Then after they've been knocked the distance we want, we set their kinematic bool to true and re-enable the nav mesh agent. :) It works pretty decently, and we're not getting any errors.

You just have to make sure you do checks, so that you aren't calling any nAgent commands such as Stop() or SetDestination() while the nAgent is disabled or you'll get NullReferences.

Show more comments

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

11 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

Related Questions

how can I set the destination of the nav mesh for multiple objects 2 Answers

Is there a built in notification when Nav Mesh Agents when destination is reached? 1 Answer

Aron Granberg Navmesh navigation not detecting objects on icosphere 1 Answer

NavMesh and rotation before movement 1 Answer

Navigate objects based on 2DTexture informations? 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