Animation detachment

Hi everyone,
I would like to ask more for an advice than a technical question.

Basically what I have is a main 3d character which always runs to the right and some other 3d enemy characters which appear randomly in front of him. What I want to do is create a reaction game in which, basically, you have to click a button at the right time and a certain animation will play.

Now, to the main part, I don’t really know how to do it better, the main character will have an animation in which he throws a knife at the enemy, the knife then sticks into the enemy and after, the main character jumps over the enemy grabbing the knife, pulling it out and after the landing continues running.

Here is a quick sketch of what I mean:
alt text

And now, the question, how would it be possible to make such kind of actions?

I thought of doing separate animations involving both characters for each situation, basically one animation per every type of encounter, but this solutions seems kind of noob’ish :slight_smile: which is going to require a lot of work if I’m going to have a lot of enemies and also there is an issue with synchronizing the animation at the right time.

Another solution I thought of was to script the knife to fly to the enemy’s head, stop as soon as it collides and detach from the enemy as soon as it collides with the hand of the main character, but then again, I would have to detach and attach the knife to the main character all the time because it is going to be a child of the main character’s hand. This solution also has issues with animation synchronizations.

I’m trying to figure this out for 3 weeks already and can’t really come up with a good solution, if anyone had any experience with a similar idea like this then please share, I will greatly appreciate it .

I did not find anything that could help me with this on unity answers nor by searching the web.

Thanks in advance :wink:

At first glance, I’d probably try to solve this by:

  • Target a particular location, based on a rig bone plus some offset (possibly 0, but even so)
  • Lerp the knife between origin and target positions (“throw”)
  • On impact, attach the knife so that it animates with the target
  • When it’s time to “grab” the knife, repeat the process more or less in reverse; it should look okay, as long as the character’s hand is close enough that the knife isn’t “flying”

With games, you’re allowed to fake everything. It only has to look real.

The problem I anticipate there, which I think you’ve already mentioned, is how to handle the possibility that the knife is flying toward a moving target.

Easy solution, of course, is try not to do that. :wink:

If you have to, though, you could try sampling the animation state ahead by some amount of time. Sounds expensive (and very tricky if you can’t predict what that state will be ahead of time), but you might be able to get away with it.

You might try building the animations such that the target point is always predictable, but that seems to me like a solution that’d work by coincidence rather than by design.

The closer this is to a pre-scripted event, the easier it will be. Every dynamic element adds complexity.

to me this sounds like you want the hole game done for you :wink: but here is what i have so far, you want it so when you press a button at a specific time to throw a knife right, here is how i would do this you would have a boolean that is deactivated then when it hits a collider it activates the boolean as soon as this boolean is activated you are able to throw the knife at the enemy this is your choice you could you a Yield WaitForSeconds or a OnTriggerExit function, to determine when the button is deactivated, and when you cant throw the knife again, the code from the top of my head would look something like this,

var ThrowAble : boolean;
function Start()
   ThrowAble = false;

function OnTriggerEnter(Hit : Collider)
   if(Hit.Tag == "Player");
   ThrowAble = true;
//This is your Choice now Either have OnTriggerExit Or the Yield Function.

 function OnTriggerExit()
    ThrowAble = false;

function OnGUI()
   if(ThrowAble == true){
    if(GUI.Button(Rect(10,10,100,40),"Click Me")){


This Code Will Point in the right direction, If you enter a Trigger a button will appear and when you click it a animation will be played, if you exit the Trigger The button will go Therefore, Not been Able to play the Knife Throwing animation, hope this helped you.