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