- Home /
How to move object from existing position to new position and change its animation?
Hello. This is my first time asking a question. I'm still a Unity newbie but have been a developer for years. I've spent hours trying to figure out how to successfully perform what I would think would be a simple task and, no matter what I've tried, it hasn't done the trick. I would post some code but I have nothing that is working.
Here's what I would like to accomplish. I have a room with a monster object in the far corner. I have a trigger in the doorway. When the FPC walks into the trigger I want the monster object to move across the room to a point in front of the door and stop. At that point I want to change the monster's built-in animation to change from it's "run" animation to it's "attack" animation. That's it. Move from point a to point b while running. Stop at point b and switch to the attack animation.
That's it. Nothing fancy but it's driving me crazy. I've spent hours working with different lerp examples, move examples, translate etc. I can get the monster to move correctly using the animation editor, but I don't know how to switch the animation from "run" to "attack" when it reaches the destination from within the animation window.
Thank you in advance to anyone who can offer some insight and guidance. Have a great day!
Ed
Can I ask why you're trying to animate without using $$anonymous$$ecanim? It's designed around exactly these types of tasks (animating, state machines, blending between animations)
As I mentioned, I'm very new to Unity. As a web app developer, I do what I usually do and Google my way to an answer. So I Googled to find an answer to moving objects. Almost everything pointed me towards things like lerp and the various transforms. In my way of thinking I was just going after the logical answer to how to script my object to move from A to B and, when it reached B, change the animation. I could get pieces of that working, but not all of it. I will definitely do some reading up on $$anonymous$$ecanim, though.
Is $$anonymous$$ecanim for other, less complex things? Like lets just say I have a cube that I want to transition from A to B and then transform the color. Is $$anonymous$$ecanim for this kind of thing as well?
Thanks for the help!
$$anonymous$$ecanim is used for rigged animations, such as characters, enemies, etc. as long as you have different parts you would like to animate. Someone correct me if I'm wrong, but I don't believe it can do things like the cube movement and color change (this is an instance where'd you use lerping), but it could easily do what you're looking for.
Yeah, I'm trying to move the character object as a whole from A to B and then switch the rigged animation once it hits point B.
When I heard monster, attack, run, I made the assumption that your scenario did or would eventually involve animations of rigged characters, and so recommended mecanim.
It's actually a choice how heavily you want to integrate its state machine package with your AI logic, but when you start from square one using it to help drive your character, it'll make it a lot easier later if-and-when the project requires anything complex like blending between multiple animations on rigged characters.
Basically, if you ever want blended animations, or you ever want to rely on animation status to help drive logic (when attack animation is at 50%, call ApplyDamage on target, for instance) then you should probably lean on mecanim to help by learning and integrating it early.
Otherwise any method of translating an object from A to B and triggering animations will suffice, and mecanim might be overkill.
Answer by apollo25 · Oct 27, 2014 at 05:14 PM
Use mecanim animation system.You can learn here - http://unity3d.com/unity/animation you can keep a transition from idle to running at pt A. Then you can trasform.translate to pt.B. keep another trigger enter at B. Here again you can create a transition using trigger enter to change the float. hope the guidelines help.I am a newbieas well. you will be able to use mecanim after u see the 50min tut by unity....if u have any probs with triggers ortransform.translate u can refer youtube vids or API.
Thank you all for your guidance. I'll check things out and see if I can achieve the desired effect.
Your answer
Follow this Question
Related Questions
code using lerp with input 2 Answers
Learning to move 1 Answer
Move an object down a little, then up to a position 1 Answer