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
0
Question by arain55 · Feb 28, 2016 at 07:24 PM · rigidbodyaitop down shootergrenade

Problem with AI and grenade(addExplosionForce)

so I was following a game creation series and decided to go of course to add my own things and I added a grenade and here is my following Grenade script which is attached to the player:

 using UnityEngine;
 using System.Collections;
 
 public class Grenade : MonoBehaviour {
 
     public Rigidbody grenade;
     public Transform throwPoint;
     public float throwPower;
     // Use this for initialization
     void Start ()
     {
         grenade = grenade.GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void Update ()
     {
         if (Input.GetMouseButtonDown(1))
         {
             Rigidbody clone = new Rigidbody();
             clone=Instantiate(grenade, throwPoint.transform.position, throwPoint.transform.rotation)as Rigidbody;
             clone.velocity=transform.TransformDirection(Vector3.forward*throwPower);
         }
     }
 }

and heres my explosion script which makes the explosion happened and it is attached to the grenade prefab:

 using UnityEngine;
 using System.Collections;
 
 public class Explosion : MonoBehaviour {
 
     public float radius;
     public float power;
     public float explosiveLift;
     public float explosiveDelay;
     public Transform explosionPrefab;
     public Collider[] colliders;
     IEnumerator    Start () 
     {
         yield return new WaitForSeconds(explosiveDelay);
         Vector3 grenadeOrigin = transform.position;
         colliders = Physics.OverlapSphere(grenadeOrigin, radius);
         foreach (Collider hit in colliders)
         {
             
             if (hit.GetComponent<Rigidbody>())
             {
                 hit.GetComponent<Rigidbody>().AddExplosionForce(power, grenadeOrigin, radius, explosiveLift,ForceMode.Impulse);
 
                 Destroy(this.gameObject);
             }
         }
     }
 }

so after I throw my grenade and let it explode and effect my enemies what happens is that my enemies propel back which is expected but what isn't expected is that when they propel back they become glitch and start vibrating and moving very slowly and another thing is that when they attack me they fall right through map. if u require more information ill be happy to provide it :)

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 Fredex8 · Mar 01, 2016 at 04:28 AM

How are the enemies moving towards you? Navmesh movement combined with rigidbodies seem to cause problems like this quite a lot.

It sounds like when the enemies are being pushed back by the grenade force they are still trying to move forward towards you. You should add a condition to their script that stops them from moving when they have been hit by a grenade blast until the knockback effect has finished.

Not sure the cause of them falling through the map on attack but it sounds like it is probably because their Y position is affected by the attack (due to animation or colliding with the player perhaps). If the collider is pushed beneath the ground they will obviously start to fall through it. If you can't directly address the cause of the problem then manually setting their Y position back to what it should be when it starts to decrease too much is a temporary solution.

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

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

Pros and cons to using Navmesh Agents over custom-made AI? 1 Answer

Random.insideUnitSphere: 180° possible? 1 Answer

Using Rigidbody physics to move an enemy with NavMeshAgent - De-sync issues 0 Answers

Ai Destinations not changing when using length of raycast, 0 Answers

Enemy pathfinding script for a 2D top down shooter game 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