Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Sword swings and collsion detections while moving.  (Read 1050 times)
Aion
Customers
Community Member
*****
Posts: 144


WWW
« on: August 21, 2008, 12:29:12 PM »

I'm trying to figure out the best way to detect sword swing hits. Here is the situation:

-2 actors, one has a custom designed sword, attached to a bone.
-Both are animated and running around,
-there is a swing sword animation and when that happens i need to detect if the sword went through the other actor.

I was going to use Physics.TestCollision, however, the issue is if i just check every frame the animation might move too far ahead, with one frame having the sword about to hit the 2nd actor, and the next already having passed them.

Ive been using tvphysics to do ray collisions faster, but i dont do any kind of simulation yet.

How would you do it?
Logged

HRuivo
Community Member
*
Posts: 18


« Reply #1 on: August 21, 2008, 12:53:08 PM »

hey, I have been think on that too and the best way I found would be to cast a ray to each of the actors and if the distance is not longer than the swing and the enemy is in front of you, you hit him.
But this is all theory haven't coded it yet, but its the way I would probably do in future.
Logged
Aion
Customers
Community Member
*****
Posts: 144


WWW
« Reply #2 on: August 21, 2008, 01:32:12 PM »

that might work, except i would like it to be much more accurate, and all animation and weapons are custom made, so its not possible to get the swing length.
Logged

WEst
Customers
Community Member
*****
Posts: 937

Daniel Martinek


WWW
« Reply #3 on: August 21, 2008, 01:58:16 PM »

You can try to create some hitboxes by using the bone information supplied by TV3D, and then do a simple BB test with the swords BB. It wouldn't be awfully fast, but it should work.
Logged

Greetings

Daniel Martinek
Technical Director
23 Volts
Aion
Customers
Community Member
*****
Posts: 144


WWW
« Reply #4 on: August 21, 2008, 02:05:17 PM »

that method has the same issue as the physics.testcollision (except its less accurate)
its fine until the animation happens fast enough to miss the other actor.
Logged

WEst
Customers
Community Member
*****
Posts: 937

Daniel Martinek


WWW
« Reply #5 on: August 21, 2008, 02:25:39 PM »

Not necessarily, you can create a special BoundingBox for the Sword, that stretches over 2 frames, but I would consider this as quite heavy to compute. You can do several raycasts (which is very heavy too), but else there isn't much to do about this, this is simply a common problem with collision, you can't compare much if you don't have the data. You could use substeps for the animation (call Actor.UpdateEx with a fraction of the TimeElapsed) and test with the substep position, but I think there isn't much left else.
Logged

Greetings

Daniel Martinek
Technical Director
23 Volts
Brac
Customers
Community Member
*****
Posts: 363


« Reply #6 on: August 21, 2008, 02:36:20 PM »

How about a tight fit OBB, then just do a raycast into that box.
Keeping the OBB is 1 matrix mul per actor and the raycast is very fast.
Logged
Aion
Customers
Community Member
*****
Posts: 144


WWW
« Reply #7 on: August 21, 2008, 02:44:55 PM »

Well, i was kinda hoping i could use the physics engine somehow. When a box is moving quickly in a physics engine, how does it handle this kind of issue?

Thats what i want to do, except instead of bouncing back, i want it to trigger a hit.
Logged

WEst
Customers
Community Member
*****
Posts: 937

Daniel Martinek


WWW
« Reply #8 on: August 21, 2008, 03:04:55 PM »

Well, i was kinda hoping i could use the physics engine somehow. When a box is moving quickly in a physics engine, how does it handle this kind of issue?

It's quite easy: it normally doesn't  Wink

But to provide better collisions they use substeps, and also some sophisticated collision algorithms, but they can't fully overcome this problem, they only hide it better.

You can try using adaptive raycasts:
  • Get the tip of the sword in this and the last frame
  • Get the length of the segment between the tips
  • According to the distance create a number of raycasts

It's more accurate than normal raycast, but ofcourse not perfect.
Logged

Greetings

Daniel Martinek
Technical Director
23 Volts
Aion
Customers
Community Member
*****
Posts: 144


WWW
« Reply #9 on: August 21, 2008, 03:22:06 PM »

my problem then is, that every item is custom, and i can never know the tip of the sword. because sometimes its a guitar, and sometimes its a giant robot hand on a stick.

perhaps i can do a combination of calculations on the difference in the swords matrix, and get some kind of number of tests to do... but it seems like i should be able to use TV's physics engine to accomplish this automatically. Tongue
Logged

HRuivo
Community Member
*
Posts: 18


« Reply #10 on: August 21, 2008, 04:25:54 PM »

Why don't you create a variable to store the weapon's hit length? and that length will be then used on the ray test.
And to easily determine its length you can create a simple tool where you can increment/decrement the weapon's length value which is shown as a colored ray, starting on where the player got his hands.
This is my thoughts, I hope its nothing ridiculous heh.
Logged
WEst
Customers
Community Member
*****
Posts: 937

Daniel Martinek


WWW
« Reply #11 on: August 21, 2008, 05:18:02 PM »

perhaps i can do a combination of calculations on the difference in the swords matrix, and get some kind of number of tests to do... but it seems like i should be able to use TV's physics engine to accomplish this automatically. Tongue

That's a bit a problem, because afaik Netwon 1.6 doesn't support animated physics objects very well. But Newton Archimedea should support it, so either do it yourself or wait for the implementation of Newton 2.0 (or implement it yourself).
Logged

Greetings

Daniel Martinek
Technical Director
23 Volts
Aion
Customers
Community Member
*****
Posts: 144


WWW
« Reply #12 on: August 21, 2008, 06:05:36 PM »

the animated actors are not a problem, if thats what you ment, i can just do actor.getdeformedmesh -> and create a physics body from it. then do the swing tests on that.

oh well... perhaps i will just do stuff based on my animation timing and call it not really good enough, but oh well. :\
Logged

jviper
Community Member
*
Posts: 2058

Discipline in training


« Reply #13 on: August 21, 2008, 06:19:51 PM »

Actually what you do is attach a physics body to yout sword. Give the enemy actors/meshes physics bodies (useally with actors, cylinders work for moving actors). when you run the physics simulation, grab the TVPhysics Collision Array. Check the collision array if the sword collided with another actor body.
Logged

JAbstract.....Don't just imagine, make it happen!
Lyrical
Customers
Community Member
*****
Posts: 465


WWW
« Reply #14 on: August 22, 2008, 07:11:27 AM »

Here is another aproach.

disable collisions on your sword first
Draw a raycast along the sword blade
animate the raycast from hilt of sword to the tip of the blade
then just check the collision result for a hit

hope this gives you another option
Logged
TecnoBacon
Customers
Community Member
*****
Posts: 292


WWW
« Reply #15 on: August 23, 2008, 08:27:26 PM »

A method used in combat simulators is to keep data about a sphere ( radius , position ) and relate it to the tip of the sword.
if the the tips are in both sheres then a close impsact if probable, if one or the other is in exclusivly then it is a farther impact and if niether is in the other than it is a blade impact test only.
it is much faster to estimate than to calculate, and tables are also a clever way for fast stuuts etc,  you can even have the animation ranges in them.
Logged

www.TecnoBacon.com - the other side of the Bacon family! 3D Development, Music and more.
jviper
Community Member
*
Posts: 2058

Discipline in training


« Reply #16 on: August 23, 2008, 10:34:00 PM »

Lyrical: THe problem with that method still exists. With a fast moving sword collisions may get skipped.
Logged

JAbstract.....Don't just imagine, make it happen!
Lyrical
Customers
Community Member
*****
Posts: 465


WWW
« Reply #17 on: August 25, 2008, 08:36:50 AM »

Very true jviper,

    you could also use multiple rays. or even a capsule around and use the physics engine to detect collisions although this method would be a little harder.

When i did my mele weapon system i use a ray from the body position to say 1 meter in front, if the ray hit something then so would the sword. however this isn't as acurate as you may want it.


Logged
sciophyte
Customers
Community Member
*****
Posts: 246


« Reply #18 on: August 25, 2008, 12:46:42 PM »

could you perhaps make an invisible tri-strip following the path of the sword (like how they do sword swing effects) and just calculate collision on tri-strip?  once there's collision or animation has ended, u unload strip and good to go.
Logged
Kain Mikado
Community Member
*
Posts: 13

Random Cynical Prick


« Reply #19 on: August 27, 2008, 01:04:12 AM »

I'm talking out of my ass here but how I always imagined it would be done is when a sword moves, there is a physics object like a plane if possible that is created in the area that the slash was for the time that it was there. I would assume you could stretch the plane into necessary shapes if you can even make one. I think it may be tricky to get them to appear in the same place the animation goes off. But if so it seems like it would work.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks