Hey guys. I was wanting to know if any of you knew how to procedurally set key frames using an array of weigh points.
Id like a camera to follow an array of numbered weight points via animation, but I want that animation to be created at startup so I can change it in editor…
Thanks
sounds like you are looking for ways to animate your bones within unity, right?
You could specify have 2 arrays, one Vector3[ ] containing position and a float array containing time between waypoints. Just Lerp the transform of the camera between array indices using the time in the float array to control the Lerp speed.
Im just trying to animate the position of gameobjects procedurally.
Hey guys im :!: bumping :!: this cause I think it would help along with a lot of things in my group. If anyone knows what to do I would greatly appreciate it! We are working on a different way of setting up the camera.
Thanks!
Jake 8)
animating the position is just a mater of setting a new position or applying a force.
For the first unitys own animation editor (if you use Unity 2.1) or AniMate from the unifycommunity wiki might be your friend.
Yes but I’m not trying to move it in a conventional way.
There is only moving the object or not moving it.
There is no 3rd version.
If you are talking of mesh deformation then you need to do that as explained above by modifying the vertices manually.
Ok let me specify. You can animate a cameras transforms by hand within unity and that’s fine and dandy. But its a pain in the ass when you must animate something through a level when the level constantly changes. In order to fix this I’d like to procedurally animate something at the start() so I don’t have to animate by hand. I’ve been using unity for over 2 years and I understand how it works for the most part.
But what kind of animation.
Transform changes or changes in the way the animation editor in unity 2.1 would have allowed it within a static environment?
Sounds like something in the range of Behave and/or the path lib + potentially ani.mate which will make simple change over time animation straight forward.
Animating of a skeleton object?
Same as above but with additional usage of the locomotion system
I hope I formulated the question better, because I’m having some serious problems understanding what you are looking for and without that knowledge there is no solution that could be pointed out.
lol sorry. I am having a hard time explaining, and im getting frustrated like I imagine you are!
I will post a script I have made later on tonight when I get home and you can see kinda what Ive done, and hopefully tell by what I have done what I am trying to achieve.
Sorry for being so frustrating
Here is the code I am using. It sorta Animates the camera but not completely, anyway, hopefully this helps explain what I im trying to do!
@script RequireComponent(Animation)
var trans : Transform[];
var tInc = 2.0;
private var t = 0;
private var w = 0;
function Start() {
var clip = new AnimationClip();
clip.SetCurve("", Transform, "localPosition.x", AnimationCurve.Linear(t, trans[0].position.x, 10, trans[trans.length-1].position.x));
clip.SetCurve("", Transform, "localPosition.y", AnimationCurve.Linear(t, trans[0].position.y, 10, trans[trans.length-1].position.y));
clip.SetCurve("", Transform, "localPosition.z", AnimationCurve.Linear(t, trans[0].position.z, 10, trans[trans.length-1].position.z));
animation.AddClip(clip, "weight");
animation.Play("weight");
}
function Update() {
animation.Play("weight");
}
There was a for loop in there but I took it out for some reason earlier (this is a older project). But anyway, that script puts a new keyframe in the “clip” curve variable, and it will animate the last 2 weigh points, but not from point 1 to point 4. (As seen in the picture below)
Looking at your script, it looks like it will animate the camera’s position from trans[0] to trans[trans.length-1] without touching the points in between. Is that what it’s doing?
If so, that’s because you’re using AnimationCurve.Linear to set the curve. The Linear function just does a straight line from A to B. It doesn’t take into account the other keys in your array or even that the points you’re setting are in an array at all, since it only sets two keyframes in the curve - the ones you explicitly define as arguments in the method call.
What you need to do instead is define a curve for each property with an array of Keyframes containing the time and value of each waypoint, for example like this (I mostly use C#, so apologies if this javascript code is a little mangled):
var xFrames : Keyframe[] = new Keyframe[trans.length];
var animationLength : float;
for (var i=0;i<trans.length;i++)
{
xFrames[i] = new Keyframe((i as float / trans.length * animationLength, trans[i].position.x);
}
var xCurve = new AnimationCurve(xFrames);
Repeat for each property you want to animate, and then add those curves to your clip in place of the AnimationCurve.Linear one you have now.
yeah, like I said, I did have a for loop in there that itterated through the transforms in the array, but I forget why I changed it to what it is now. I will try your way and see what I come up with.
Thanks
OK works great! Thanks a bunch…