I've created a character that moves it's sword around using mouse input (ie moving the mouse up makes him raise his sword). This is not an animation, it is transforming the model via script. I want the damage system to take in to account how fast the user is moving the mouse, where a slow movement does little or no damage and a big swing could take off the limb it hits.
I can't find the right way to make collsions work. I made the sword a kinetic mesh collider attached to a rigidbody with a trigger. I can get collisions using OnTriggerEnter, but it seems that i cant get the colliosn to pass vector/magnitude information to try and determine how fast it hit. The sword also passes straight through.
If your motion of the sword is based on the mouse movement, you could actually use the mouse delta values as your "damage amount" value.
Another method would be to create a dummy gameobject which is parented to the tip of the sword, and measure its position each frame. You can then calculate its speed by comparing the difference between the last measured position and the current position.
Eg:
var swordTip : Transform; // drag a reference to the swordtip dummy object here
private var lastTipPosition : Vector3;
function Start() {
lastTipPosition = swordTip.position;
}
function Update() {
var swordSpeed = (lastTipPosition - swordTip.position).magnitude;
lastTipPosition = swordTip.position;
}