25
\$\begingroup\$

I'm working on a throwing knife type weapon where a player free aims and then throws a knife. The knife spins through the air and on collision stops spinning and parents itself to the object it collided with. The spinning is handled via animation while the path of the knife is handled by physics.

One problem I'm facing is how to make sure that when the knife collides with an enemy that the knife will be facing towards them. At the moment what is happening sometimes is that the knife embeds into an enemy handle first. Which is obviously unrealistic. At the same time, I think it would be quite unreasonable for the knife to only "hit" the enemy if it collided blade first, since the rate at which the knife spins is beyond the player's control.

I've been watching a lot of slow killcam footage of similar weapons and each time the weapon is thrown it spins through the air and magically always ends up with the blade pointing at its target. For a game where the throwing distance will be consistent, this is quite straight forward to do. But I'm not quite sure how to predict this since there are many unpredictable factors involved eg. direction of the knife, rotation of the knife, position of the enemy, distance from enemy etc. If possible, I would prefer not to have to use complex prediction logic since the game will be for fairly low end devices. Is there a "smoke and mirrors" way to solve this?

Example: https://youtu.be/0fav8lFpBko?t=42s

\$\endgroup\$
  • 15
    \$\begingroup\$ The knife always hitting a target blade first isn't realistic either, in particular when we talk about a moving target. \$\endgroup\$ – Theraot Mar 15 '17 at 1:57
  • 1
    \$\begingroup\$ Depending on the flavour of the game, there are a number of knife-throwing styles that do not spin the blade. Usually they're using knives specifically designed to fly in a stable fashion though. \$\endgroup\$ – Perkins Mar 16 '17 at 0:19
  • \$\begingroup\$ if the center of mass of the knife is significantly closer to the handle end rather than blade end, and the knife rotation speed is much greater than it's travel speed, then it might actually hit the target with the blade always. that would be a very strange knife though, and a very strange creature who may throw it like that \$\endgroup\$ – Sarge Borsch Mar 16 '17 at 8:07
  • 2
    \$\begingroup\$ This issue is prominent enough that there's a TVTropes article about it: The Blade Always Lands Pointy End In \$\endgroup\$ – Mason Wheeler Mar 16 '17 at 17:37
  • \$\begingroup\$ I also like the distinction made in the question. If you switched the rotation to also being handled by the physics engine, you might have enough information then to make a calculation at collision time to see if the knife-end was facing the target well enough or not. Either that, or keep animation, and just pre-bake the values where animations of the knife are pointing forward and compare the current animation frame to see if it is within that range or not. \$\endgroup\$ – Pysis Mar 16 '17 at 19:18
35
\$\begingroup\$

Fake it

Look at the video you linked, watch it in slow motion... eh, what is that? The camera jumps at the end, and the knife is already in the helmet of the target.

Just fake it. Once the distance from the knife to the target is small, jump cut to the knife magically in the target.

Edit: you can check if it will hit a target using the convoluted prediction, and then pretend it did hit blade first, then show an animation where the target does not move and the knife kills it.


The convoluted prediction

since the rate at which the knife spins is beyond the player's control.

That is right. It is beyond player's control. However, not beyond your control...

If you can compute the distance the knife has to travel, you can make the rotating rate such that the knife will hit blade first.

Now, it does not make sense to make this prediction in mid-flight, because the knife would have to adjust if an obstacle gets in the way. Therefore, you would do it when you throw.

The fact that you have to follow a parabolic path to hit test makes it more complicated than a simple ray cast. I would suggest getting the equation for the parabolic motion that correspond to the knife throw, and evaluated it at given intervals.

It is also possible to find the distance of obstacles to the parabola, by finding the closest point in the parabola to the position of the obstacle, and then do a collision check with that point.

Once you know how much has the knife has to travel, you can divide it into an integer number of rotations, so that it will hit blade first. Edit: or an integer 0.5 depending on how you throw.

Of course, the obstacles would have moved by the moment when the knife gets there…


Be realistic

You will not make the knife hit blade first 100% of the times, in particular with moving targets. Just embrace that, a throwing knife is not a reliable weapon. So have the alternative of having it bounce when it hits handle first. You can check if it hit handle first by checking its orientation and comparing it with the direction to the collision point.

\$\endgroup\$
  • 1
    \$\begingroup\$ Ah I did not see the jump cut, how clever yet so simple. It's very obvious when I watched it frame by frame as you suggested. \$\endgroup\$ – FrontEnd Mar 15 '17 at 3:18
14
\$\begingroup\$

If you know ahead of time where the knife will land - like in those kill cam footage, which is most definitely produced after-the-fact - just calculate the right rotation speed based on flight distance and number of rotations desired. Throwing knives leave the thrower hilt-first, so it needs to rotate N+0.5 full rotations1, where N is usually at least 1 but could be more based on the thrower's skill level or how cool you want it to look: more spins = more cool.

If you don't, it's ok to cheat by fixing the rotation on hit, and perhaps hide it with a blood splatter. Like a magician, if you do it quick enough the player is not going to notice.

Of course, none of this is realistic. In real life, knife throwing is really hard and requires a lot of practice if you want the knife to land blade-first. The thrower needs to be fully aware of the distance and alter their throw accordingly, otherwise the knife will hit hilt-first.

1: There are some styles where the knife goes blade-first too.

\$\endgroup\$
  • 4
    \$\begingroup\$ +1: blood splatter. Good, magic tricks. Edit: or a dust cloud for the non-gore edition. \$\endgroup\$ – Theraot Mar 15 '17 at 2:17
  • 2
    \$\begingroup\$ @Theraot and/or make the rate of spin fast enough that the viewer can't really keep track of which way it's pointed. \$\endgroup\$ – Perkins Mar 16 '17 at 0:14
14
\$\begingroup\$
  1. Calculate the straight line distance to target.

  2. Each Frame set the angle of the knife to be 2PI*(remainingStraightLineDistance)/(originalStraightLineDistance)*DesiredNumRotations.

The spin ratio will vary slightly if you don't move the knife in a straight line but no-one will ever notice.

If you don't pre-determine the target (i.e. you're just throwing and using physics to see what it hits) then you will need to fudge this but you can use the same principle of looking at what target it's likely to hit and adjusting the spin to be correct for that target.

\$\endgroup\$
4
\$\begingroup\$

Real throwing-knifes are designed to have a very high chance of hitting blade-first. Design your knives accordingly.

Collection of throwing knives from Wikipedia: Collection of throwing knives from wikipedia

You want the center of mass, and thus the center of rotation, as far away from the tip of the blade as possible. This will increase the odds that the blade will spin around into hitting position before the end of the handle gets there.

The blade is typically long and thin, to protrude as far as possible from the center of mass while adding as little mass of its own as possible. Additionally, there is a often disk-shaped or spherical counterweight at the end of the handle, which interestingly I don't see in any of the knives from the Wikipedia image.

The knife is thrown by holding the tip of the blade and arcing the handle into the direction of throw.

\$\endgroup\$
2
\$\begingroup\$

For a "smoke and mirrors" way, you can have the center of rotation of the knife (i.e. the center of mass) near to the handle (i.e. non-pointy part). This way, if the rotation speed is high enough compared to the knife's velocity, it can be guaranteed that the tip of blade will collide with the target and not any other part.

There's some calculation to get which is the minimum rotation speed given the center of mass and dimensions, but should be straightforward. Note also this doesn't imply anything about the angle of the hit.

\$\endgroup\$
1
\$\begingroup\$

Perfect knife thrower?

At the moment, you say you are spinning the knife through animation. What parameter are you using to control the angle? Frame number? Game time? Scaled by an arbitrary spin rate?

If instead you used the parameter (distance moved)/(total distance to target), with the appropriate scaling by pi and (number of turns+0.5), then the knife would indeed always magically arrive point first.

\$\endgroup\$
  • \$\begingroup\$ The first part of this question appears to ask for clarification. It should probably be made as comments on the question. Could you elaborate on your proposed method for magically arriving point first? For example, you say "with the appropriate scaling by pi"; what scaling? It s fair to assume that if the user has to ask, they may not understand what the appropriate scaling would be. \$\endgroup\$ – Gnemlock Mar 15 '17 at 7:12
  • \$\begingroup\$ @TimB did a better job of explaining it, but the Neil's proposed solution is a good approach. Modify the speed of your spinning knife animation so that when it reaches the target the knife is in "the pointy end goes in the other man" position. This is a lot easier (to program, AND computationally) than computing parabolic trajectories involving moving targets, etc. As for "the appropriate scaling by PI" that would likely just be 2, given that number_of_revolutions is another variable in Neil's pseudoequation. If it's keyframe animation, then you just scale your index and forget about pi. \$\endgroup\$ – A C Mar 15 '17 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.