Currently I am mucking around with unity and I would like to make a simple door opening animation, however my problem is that when my animation runs it goes from Y = 0 then slowly goes to Y = 90 which is good but ideally what I would like it to do is Y = (Anything) and then my animation goes Y + 90.
So whatever angle my animation starts of at it will always end in (Original Y Axis) + 90.
Sorry if this is posted in the wrong section or I am unclear but I would like a way to know how to do this. I know it is a simple thing and there are probably already answers out there but I have been unable to find them, please let me know if there is any setting I can change or if there is a completely different way to do it.
I have also seen animation curves and I am wondering if they are what I need to be using.
I do have a decent bit of coding experience with unity however I still have this problem. What lines should I use transform.rotate or just use code to edit the animation?
To be honest could you tell me how to create a simple roasting object over time script. I know there are quiet a lot of them but none have ever worked for me.
Thanks,
-e111s
private void StartAnaimation()
{
StartCoroutine("RotateTo90");
}
private void StopAnimation()
{
StopCoroutine("RotateTo90");
}
private IEnumerator RotateTo90()
{
//change this variable for diffrenent turning speed
//this can be also moved in global declaration
float speed = 1f;
//the final angle you want to achive
//this can also be Quaternion.Euler(endXAngle, endYAngle, endZAngle);
Quaternion destination = Quaternion.Euler(0, transform.rotation.eulerAngles.y + 90, 0);
//time quantifier
float t = 0;
while (t <= 1)
{
t += Time.deltaTime * speed;
transform.rotation = Quaternion.Slerp(transform.rotation, destination, t);
yield return null;
}
}
Here you go.
If you want to understand exactly what is happening here you should search tutorials on Corutines and on Lerp function
Thank you this was very helpful,
However, I have another question, so how would I go about doing a very complex animation for example an animation of someone being tackled to the ground or another animation that involves lots of bones moving.
Thanks,
Well it depends from animation to animation. When you know exactly the state of an object in every frame of the animation (this always true for humanoid) you use animator.
The idea is that animator has frames of animation. In each frame, you define an exact value (key frame) for the property you are animating (or the value is interpolated based on animation curves). This values mast be constants. In your initial problem, you wanted your final rotation to be start + 90. This means that the last position is not constant, but it’s a variable. With bone animation, everything is constant. In each frame, each bone has a predefined position and is constant based on the time that you play the animation. (each time the animation looks the same).
I hope this clears some doubt.