Sign in to follow this  
amorgan

Animations and Bounding Boxes

Recommended Posts

Arising from another thread, currently BabylonJS does not change the bounding box of a model if it is moved by an animations with bones. This makes sense, because the animation is not changing the object, but the vertices of the object.

 

My problem arose because I have a character mesh with a sword (two meshes). I have an attack animation where the character mesh is swinging the sword. In an ideal world the bounding box would move with the sword and I could use that detect collisions with an enemy using the OnIntersectEnter Action Trigger.

 

I have some work around solutions to this specific problem, but I would think this could be useful for other scenarios as well. Not knowing much about the inner workings, I would guess you could calculate the bounding box during animation similar to doing a precise mesh calculation. Though it would be nice to do a normal bounding box that was just a max box dimension. It might be usefull for these to be variables:

 

1) bounding box to track animations - boolean

2) whether the bounding box is precise or simple (though this might be apart of the Action manager Trigger) - boolean

 

Some of that is thinking out loud, what do you guys think?

Share this post


Link to post
Share on other sites

I would recommend estimating the hit rather than using the action manager for this. Define a range to all your melee weapons, then "if attacking and enemy distance < attack range, play(deflect animation) and miss"

 

If I'm not mistaken, babylon has too loop through all action manager events for every frame / trigger, so while this may work for 1 enemy, if you have... 20, then it has to check the event for all 20 to see if you're action should be triggered. Best to simplify your approach when possible.

 

I don't like hit boxes unless they're absolutely necessary. especially for something with performance limitations like this that runs on javascript.

Share this post


Link to post
Share on other sites

So I've been trying to think this through. Calculating whether or not something is a hit for an object like a sword should be easy enough. Get distance from enemy and if it's facing you or blocking, and calculate it in one shot. A projectile on the other hand is a little more dynamic, so it seems like using an action manager or live calculations might not be too much different? Not sure how heavy the OnIntersectEnterTrigger and Actions are, but I feel like it should be taking advantage of the engine if I am already doing collisions. Though I am not sure how or if that is optimized.

For this type of scenario, It would be awesome to be able to specify whether or not a specified mesh of animation has it's bounding box follow, whether or not it is implemented with bones.

Thoughts?

Not sure if this is the intended usage of the OnIntersect Triggers, for a game like scenario, or how scalable it is, to reddozen's pont, which I have been strugglin with and have found some solutions for scaling to N.

Share this post


Link to post
Share on other sites

A bullet can still have a range, and you have to render it's location per frame, so it's still a distance calc per frame. What I would probably do is use a more finite octree, and then test distance to all targets in the bullets active lowest tree, and take the closets target that's in range to hit. If it's explosive, then that impact point is the epicenter. FPS games are very calculator intensive with as many bullets as you could have flying that need to be calculated.

 

I would honestly recommend using a client server setup and off load as much of the calculations to the server as possible. You will have to do a lot of testing to see what the fastest way to calculate everything is. i would push out a lot of bullets and see which method will save you the most overall frames. i think it's the only way you'll be able to find out.

Share this post


Link to post
Share on other sites

Note, I am newer to collisions and this side of things. That definitely makes sense, what I am wondering is, how is this different then using a collider system that is already in place (other than the advantage of using a server to do the grunt work if it's just calculations)? I feel like the system is already there to determine if a moving object hits something, in addition I have to already be animating/moving the object. It almost seems redundant, unless the collision method is indeed way more costly on processing (which makes sense if it is examing all vertices, etc). Granted this is probably being pretty naive on how the collisions are actually calculated.

 

So what you are telling me is that I will actually have to do some real work :( hahaha

 

The convenient part of about (in an ideal world) using the Actoin manager and collisions is that I would not have to redescribe the animations mathematically, but I'm sure to optimize this, I will have to do this. Granted I could also see a scheme where I am using the position of a mesh or it's vertices and instead of calculating it's position based off of it's mathematical trajectory...hmmm.

 

On another note (not really), is it possible to assign an objects position to a vertex's position, other than just updating it each frame manually. Sorry thinking out load again via typing.

Share this post


Link to post
Share on other sites

You shouldn't have to care about the animation state with what I'm referring to. for a sword, Just trigger it to play and then test range for hit or miss.

 

Bullet would be a little different. I'm not sure this would really be an animation as much as it's just a translation of X units per second. Wouldn't want to calculate a bullet location per frame as frames can vary, but I would test for a hit every 1~3 frames, maybe more depending on how slow your bullet moves, and how accurate you want the test.

Share this post


Link to post
Share on other sites

Yea a bullet is much more simple, let's replace it with, let's say, a boomerang. You could see how that could be apart of the animation, since it comes back to the player and is not a simple linear path. It doesn't have to be part of the animation, but just an example. A boomerang might be a bad example since it would move independently of the player's position, but let's pretend it doesn't.

Share this post


Link to post
Share on other sites

Anything to do with battle can basically be expressed as an attack range.

 

If we want to take a boomerang as an example, it's just like the bullet in that you would look at position then range where range would define how big it is.

 

I know what you mean though. It's a fight over accuracy, where you have to make a choice between exact hit vs estimation of hit.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.