x


Collisions for process animated character

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.

Help!

more ▼

asked Jun 03 '10 at 08:17 AM

Ben 6 gravatar image

Ben 6
31 1 1 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;

}
more ▼

answered Jun 03 '10 at 09:42 AM

duck gravatar image

duck ♦♦
41k 92 148 415

Great idea. But is there any way I can get the physics engine to handle the collissions ie the sword will stop when contacting the player model? I figured that changing isKinematic = false on trigger makes the limb fall off. haha.

Jun 03 '10 at 10:44 AM Ben 6

For that you might need to look at setting up configurable joints between your character's arms and body, and setting targetRotation value based on the mouse input.

Jun 03 '10 at 11:13 AM duck ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2497
x336

asked: Jun 03 '10 at 08:17 AM

Seen: 891 times

Last Updated: Jun 03 '10 at 08:17 AM