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 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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

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

LocalPosition change affecting actual Position? 1 Answer

gameobject position lerp 0 Answers

Lerp Confusion 1 Answer

Creating points for robot (End Effector) to go through them 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