- Home /
Animating an arc
I'm trying to animate a bird moving from one location to another in an arc.
I based my code off the answer to this question: http://answers.unity3d.com/questions/11184/moving-player-in-an-arc-from-startpoint-to-endpoin.html
The problem at the moment is that the animation isn't all that smooth - it starts really quickly and disappears from view but then takes a long time to fly down to the ground at the end. I thought it would just be linear but perhaps I'm not understanding something... Any ideas?
Thanks in advance, sorry if this is a pretty basic question.
function moveBird() {
var t : float;
for (t = 0.0f; t < 1.0f; t += Time.deltaTime / animTime) {
// calculate straight-line lerp position:
var currentPos = Vector3.Lerp(startMarker.position, endMarker.position, t);
// add a value to Y, using Sine to give a curved trajectory in the Y direction
currentPos.y += trajectoryHeight * Mathf.Sin(Mathf.Clamp01(t) * Mathf.PI);
// finally assign the computed position to our gameObject:
transform.position = currentPos;
yield;
}
}
Is this something you have to do in code only? Seems it would be straightforward with keyframed animation.
I haven't tried Slerp yet, I heard that this was a better way to do it.
I'm going to be doing this on a number of different objects so I need something that I can reuse. Don't think keyframe animation would help then?
Your answer
Follow this Question
Related Questions
how do i stop an animation looping? 2 Answers
How to make animations 0 Answers
Unity3D Destroying animation after its played 1 Answer
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers