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 Bovine · Sep 24, 2011 at 09:37 PM · animateanimationcurvelineargarbage collectionefficient

Better way of Animating linear movement than AnimationCurve.Linear()?

Hi All,

We are developing a 3D RPG game for iOS, but movement is restricted to a tile based view similar to many retro titles such as Dungeon Master.

I've been moving the player using physics, but I've just re-worked the collision system so that we don't need to rely on the collision model and instead we have a pre-baked map of whether a tile can be entered and how one can move from tile to tile, so I am wondering if it is cheaper to move the player by animating them from tile position to tile position, given that I already know these positions and whether the tile is free or not.

So I can do this by creating an AnimationCurve via AnimationCurve.Linear but I presume this is creating a new curve, but I wonder if it's coming from a pool of curves and whether by using this I will (or won't) increase garbage collection. Were I on pro I'd profile it to see, but I am not sadly :-(

I was hoping to create one animation clip, squirrel the curves and keys away and update them but this doesn't seem to work and results in a lot of method calls compared to the code below:

 public class BVMap2DController : MonoBehaviour
 {
     AnimationClip m_anim;
     Transform m_trans;
     Animation m_animation;
     
     const string m_clip_name_move = "M";
     
     void Start()
     {  // get local transform matrix & animation
         m_trans = transform;
         m_animation = animation;
         
         // create the animation clip for moving in 3 dimensions
         m_anim = new AnimationClip();
     }
     
     public void AnimateToPosition(ref Vector3 dest, float speed)
     {  // play the animation
         m_anim.ClearCurves();
         Vector3 pos = m_trans.localPosition;
         AnimationCurve curve_x = AnimationCurve.Linear(0, pos.x, speed, dest.x);
         AnimationCurve curve_y = AnimationCurve.Linear(0, pos.y, speed, dest.y);
         AnimationCurve curve_z = AnimationCurve.Linear(0, pos.z, speed, dest.z);
         m_anim.SetCurve("", typeof(Transform), "localPosition.x", curve_x);
         m_anim.SetCurve("", typeof(Transform), "localPosition.y", curve_y);
         m_anim.SetCurve("", typeof(Transform), "localPosition.z", curve_z);
         m_animation.AddClip(m_anim, m_clip_name_move);
         m_animation.Play(m_clip_name_move);
     }
 }

I've not dabbled in this area before, so I'm open to more efficient ways. I wasn't sure what title to go with, partly I'd like to know about the garbage collection on the phone, partly the cheapest solution.

Motivation for this is that I wanted to push the heavy lifting into the native code instead of doing this in Update() or within a Coroutine. Naturally removing the physics dependency ought to be quicker.

Thanks H

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 Bovine · Sep 24, 2011 at 11:51 PM 0
Share

Currently binned using animations and now using Coroutines with WaitForFixedUpdate().

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Eric5h5 · Sep 25, 2011 at 12:28 AM

I'm not 100% clear as to what your question is, but if you're talking about moving something from one spot to another, just use Lerp. See GridMove.

Comment
Add comment · Show 3 · 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 Bovine · Sep 25, 2011 at 03:36 AM 0
Share

Well I can do that.

Rightly or wrongly I've got it into my head that it's better to have fewer update methods and things done natively are more efficient, so I'm trying to avoid having an update call for each creature in my game - I could have one manager update of course that updates all creatures currently moving.

I was thinking I could create or modify an animation for each move from one tile to the next and that the animation would run more efficiently than having updating in Update(). However in trying to do this I am using AnimationCurve.Linear() which creates me a new AnimationCurve, I am doing this for each axis and creating an AnimationClip containing these curves. I can then play the clip and animate between two points but how efficient is that - there's a lot of setup; will the garbage collector run a lot more because of the AnimationCurves I am making for each movement? Would updating with Lerp be more efficient?

I guess I could also be asking how expensive Update() and FixedUpdate() are whether Coroutines() are more efficient or, as suggested, I use Lerp, perhaps in one master Update() that updates all currently moving creatures and players?

avatar image Bovine · Sep 25, 2011 at 12:22 PM 0
Share

So I've posted another question (http://answers.unity3d.com/questions/170243/how-efficient-is-update-vs-update-via-a-manager-vs.html) tackling some of the wider issues that have me exploring ways of doing this differently than just using Lerp in Update().

avatar image Bovine · Nov 02, 2011 at 02:28 PM 0
Share

I suppose using Lerp is the answer, but not quite what I was looking for.

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

Sum position with animation 1 Answer

Are Animations faster than Scripting linear interpolation? 1 Answer

Make Animated object disappear after it animates 1 Answer

How do I set ParticleSystem.startLifetime by Curve in script ? 2 Answers

my animation sprite is been block by the background 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