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 Jimmyborofan · May 29, 2018 at 05:12 PM · animator controlleranimations

Movetowards Jerky motion; plays animation, then moves

I have a gameObject: enemy, these are spawned on the fly I have created several waypoints along a 2D map. The enemy object, once spawned, is told to go to each waypoint in order before leaving the screen, the movement towards the waypoints is fine, it follows through correctly, however the movement is awful, in the video tutorial I am using the movement is smooth and there are no issues, from what I can see, the motion happens like this:


  • Enemy is spawned Enemy plays default

  • 'Walk Animation' Movetowards seems to

  • be called and the sprite

  • 'jumps/teleports' to its new position

  • Enemy plays walk Animation

  • Movetowards is called.... and so on

  • and so on


I have tried changing the speed of Movetowards, and I can get the animation and speed to run in sync, but the overall speed of the object in sync is too slow for the game to play.

I have tried looking for answers to this but all seem to suggest using 'Movetwards' instead of transform.

Here is a selection of my code that I think is the issue (public variables defined in unity are shown in bold) GameManager.cs void Update () { if(waypoints != null) { navigationTime += Time.deltaTime; if(navigationTime > navigationUpdate) { if (target < waypoints.Length) { print("Target = " + target); gameObject.transform.position = Vector2.MoveTowards(current: transform.position, target: waypoints[target].transform.position, maxDistanceDelta:navigationTime );

             } else  {
                gameObject.transform.position = Vector2.MoveTowards(current: transform.position, target: **exitpoint**.transform.position, maxDistanceDelta: navigationTime);
             
             }
             navigationTime = 0;
             
         }
     }
 }


I think it may have something to do with adding 'position' should the entire transform object be applied to the new vector2 object?

e.g.

  gameObject.transform = Vector2.MoveTowards(current: transform, target: **waypoints**[target].transform., maxDistanceDelta:3f * Time.deltaTime);


I'm unsure but it seems that leaving out 'position' (as was done in the video) seems to would cause an error, but I am a C# learner, I understand the framework and how to program, Im just learning the Grammar of C# as opposed to PHP (which I am proficient in).

Please if anyone can see the issue, please give me a point in the right direction!

Thank you in Advance.

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

Answer by Jimmyborofan · May 29, 2018 at 05:27 PM

So after a bit of looking and understanding exactly what was going on , I noticed that the navigationTime would only ever be higher than '1' as it was passed across, this meant that the sprite was moving in chunks of '1' unit at a time.

I also changed the gameObject to the enemy object by using


 void Start () {
     enemy = GetComponent<Transform>();
 }

Once I had the instance rather than using generic 'this' I think this opened other methods that were used (though I am unsure about that atm) I then used the enemy transform instance to apply the transform changes, I also looked at the movement and why it was moving in chunks, To fix it I made the conditional a lessThan and moved the reset of NavigationTime variable (it is a class attribute, float value = 0.0f ) to outside of the conditional so that the sprite would move in smaller increments, then once it hit the '1' unit (sometimes more, depending upon the delta.TimeValue) it reset itself whilst comparing its distance to the next waypoint.
NavigationUpdate is a value that by default is set to 1; I wonder if this could be changed in order to control speed? Anyway, The final method looked like this:


 void Update () {
     if(waypoints != null) {
         **navigationTime** += Time.deltaTime;
         if(**navigationTime** < **navigationUpdate**) {
             if (target < waypoints.Length) {
                 enemy.position = Vector2.MoveTowards(current: transform.position,
                 target: waypoints[target].transform.position, maxDistanceDelta:**navigationTime**);
             
             } else  {
                enemy.position = Vector2.MoveTowards(current: transform.position, 
                target: exitpoint.transform.position, maxDistanceDelta: **navigationTime**);
             
             }
             
             
         }
         **navigationTime** = 0;
     }
 }









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

140 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

Related Questions

Im using the HQ Fighting Animation FREE pack and have a problem with the end of the animations 0 Answers

Player's God animator vs separate animators? 1 Answer

animator.play() not working anymore 0 Answers

My animations started acting weirdly 0 Answers

Animator sets Default State everytime i switch an object's parent 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