- Home /
The question is answered, right answer was accepted
Animation and Position
I set a game object to play an animation to change it's position and rotation and when it reach the end an event trigger start and smooth damp the object so it positioned in front of the main camera but it wouldn't do that it wouldn't move at all
public void ChangePostion ()
{
Camera.main.transform.LookAt (gameObject.transform);
Vector3 targetPosition = ItemViewer.localPosition;
transform.position = Vector3.SmoothDamp (transform.position, targetPosition, ref velocity, smoothTime * Time.deltaTime);
}
Answer by chalkesonali · May 16, 2016 at 01:48 PM
smoothdamping is a gradual movement so it needs to be called in update function also your position is already controlled by animation curves so after completing animation you need to specify that the movement is now controlled by code and not by animation,you can do this by checking "apply root motion" on animator component.
change your code like this:
bool canmove;
void Update()
{
if(canmove)
transform.position = Vector3.SmoothDamp (transform.position, targetPosition, ref velocity, smoothTime * Time.deltaTime);
}
public void ChangePostion ()
{
GetComponent<Animator>().applyRootMotion = true;
Camera.main.transform.LookAt (gameObject.transform);
Vector3 targetPosition = ItemViewer.localPosition;
canmove=true;
}
Answer by incorrect · May 16, 2016 at 10:47 AM
It may be because Animator overrides it's position change. Try switching it off once your object starts being moved my trigger.
Thank you it worked I just make it disable the animator before making it move :)
Follow this Question
Related Questions
Animation script 1 Answer
How to check if Animator is playing 3 Answers
How to change the color of a UI cross hair using Raycasts 1 Answer
Play Animation several times 0 Answers