• 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 mgreene1 · Mar 06, 2016 at 08:42 PM · positionlerpenemyaishakegamedesign

Why are my enemies not moving after shaking?

I have an enemy using A* pathfinding to constantly move towards the player. I was working on a script that would cause them to 'vibrate' every time they were hit with a projectile. Problem is, often the enemy will no longer move after they finish shaking. It's like they won't stop lerping to the exact position they are stuck at or something, because they still retain all other functionality (they hurt to touch, receive damage and die, etc.).

Here is my code, can someone help me figure this out:

private float shakeAmount = 0f;

 private EnemyAI enemyAIClone;
 
 
 // Use this for initialization
 void Awake()
 {
     enemyAIClone = GetComponent<EnemyAI>();
 }
 
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.E)) 
     {
         //Test the shake
         StunShake (0.5f, .5f, true);
     }
 }
 
 public void StunShake (float _amnt, float _leng, bool _isExplosion) 
 {
     if (IsInvoking ("BeginShake") == false || _isExplosion == true) 
     {
         shakeAmount = _amnt;
         InvokeRepeating ("BeginShake", .01f, .02f);
         Invoke ("StopShake", _leng);
     } 
 }
 
 // Update is called once per frame
 void BeginShake () 
 {
     if (shakeAmount > 0) 
     {
         Vector3 myPos = transform.position;
         
         if (Vector3.Distance(myPos, transform.position) <= shakeAmount/30) 
         {myPos = transform.position + Random.insideUnitSphere * shakeAmount;}
         
         transform.position = Vector3.Lerp(transform.position, myPos , 1f);
     }
 }
 
 void StopShake () 
 {
     CancelInvoke ("BeginShake");

     //enemyAIClone.stun = false;
 }
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 mgreene1 · Mar 05, 2016 at 03:47 AM 0
Share

Update: I tested to make sure StopShake() is being invoked everytime. It is.

Also tested to see if BeginShake() was ceasing to invoke, also good.

I'm completely stumped. Does anyone know a little more about A* to explain this?

It is using a node system for waypoints and then RB.AddForce(Direction, F$$anonymous$$ode) for movement.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Creating points for robot (End Effector) to go through them 0 Answers

Vector3.Lerp not cooperating with me 0 Answers

How to lerp Perspective Camera to focus on an object in different Z position while Z position of the camera remain the same? 1 Answer

Lerping from one position to another not working 2 Answers

Camera registering it is at correct position when it isn't 0 Answers

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