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 /
avatar image
0
Question by surfuay · Sep 25, 2019 at 01:24 AM · movementai

Sprite "shudders" on arrival

So I have a random movement script for a monkey and it's going from place to place fine. But sometimes! it will shake like crazy when it arrives at a specific point. But it's not consistent. Here is the script and a quick video of the issue.

alt text

 [SerializeField]
 private float _speed = 32f;
 private float _closeThreshold = .1f;
 [SerializeField]
 private Transform[] _treeTopLocations;

 //The position we want to move to
 private Vector3 _targetPos;

 void Start()
 {
     //Set our first target location to where we already are
     _targetPos = transform.position;
     StartCoroutine(MonkeyMovement());
 }

 void Update()
 {
     //If we aren't close to our target location
     if (Vector3.Distance(transform.position, _targetPos) > _closeThreshold)
     {
         //Find the direction from where we are to where we want to be
         //Normalize it to get a direction rather than the whole distance
         Vector3 _currentDir = (_targetPos - transform.position).normalized;
         //Move towards the target
         transform.Translate(_currentDir * _speed * Time.deltaTime);
     }
 }

 IEnumerator MonkeyMovement()
 {
     while (GameManager.gameManager.gameOver == false)
     {
         if (UIManager.uIManager.pauseMenuVisible == true)
         {
             yield return null;
         }
         else
         {
             //Dont get a new target for 2 seconds
             yield return new WaitForSeconds(2);
             //Get a new target
             Transform newTree = TreeTopLocations();
             _targetPos = newTree.position;
         }
     }
 }

 public Transform TreeTopLocations()
 {
     int randomIndex = Random.Range(0, _treeTopLocations.Length);
     return _treeTopLocations[randomIndex];
 }


1-location-gif.gif (336.1 kB)
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

Answer by revolute · Sep 25, 2019 at 06:00 AM

There are a few cases that could be the problem.

The first one would be _closeThreshold = .1f not enough to cover the delta movement of speed 32. 32 * 0.02 (or 0.0166666..) = 0.64 (or 0.5). This is mostly likely in your case.

Next would be the movement being translated in wrong space. Translate does the vector movement in local space unless specified to world space. Since other positions are not being done wrong, I doubt this.

Try raising the threshold to 1 and see if that solves it.

Comment
Add comment · Show 1 · 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 surfuay · Oct 06, 2019 at 08:05 PM 0
Share

hey revolute, just saw your answer I will test this out. I am very sorry for the delay in seeing this. thanks for your time!

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

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

Game NPC "Guide" Movement (Much like Navi from Zelda) 1 Answer

Help with 2D AI scripting 2 Answers

AI walk through solid walls 1 Answer

Use of an AI script, and having it NOT go through walls using a character controller 0 Answers

Unity2D AI for Top Down Zelda-Type movement 1 Answer


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