Best way to calculate large scale collision

Hello there



when i mean large scale collision, i dont mean alot of collisions, i mean a single object that can collide with many things. In this case, it will be an axe, and a tree !



Im afraid of implementing the collision listener to each tree , so i can know when an axe will hit it, but i dont know if there is any performatic way of doing it. What would be the best solution for such a simple problem ?



Thanks alot for your attention !

I presume the axe swing is a fixed animation? Timing with the animations is the most efficient way to do this. If the animation lasts 0.5 seconds, then after that time play the chop sound, spray wood chips, etc.

1 Like
@Ziden said:
Hello there

when i mean large scale collision, i dont mean alot of collisions, i mean a single object that can collide with many things. In this case, it will be an axe, and a tree !

Im afraid of implementing the collision listener to each tree , so i can know when an axe will hit it, but i dont know if there is any performatic way of doing it. What would be the best solution for such a simple problem ?

Thanks alot for your attention !

You can make the trees into an ArrayList, then cast a Ray into it (Search Raycasting on jME wiki) and then you can see if you are looking in anything. Then if you are check the distance and there you go :)
1 Like

Yes its a fixed animation, and the axe is a separate Node, as all the trees are in one separate node as well.



The ray idea is intresting, however the tree is very thin, and the player view direction is controlled by the mouse.



Ill probably do it using collision rays until i get another solution , because this wouldnt work for example if i have a sword, and i want to hit something and this sword has 2 collision shapes, one with a greater damage one with a lower damage.



Thanks for the attention !

@Ziden said:
Yes its a fixed animation, and the axe is a separate Node, as all the trees are in one separate node as well.

The ray idea is intresting, however the tree is very thin, and the player view direction is controlled by the mouse.

Ill probably do it using collision rays until i get another solution , because this wouldnt work for example if i have a sword, and i want to hit something and this sword has 2 collision shapes, one with a greater damage one with a lower damage.

Thanks for the attention !

Cast a few rays in slightly different angles?

You can do a fast radius check, since the tree is circular you can very quickly test how far along the arm of the axe/sword your impacted.

Actually where is the problem creating one coliison lsitener and just for eacht tree add it?

Where is the performance hit with that?

Im not sure, it was a guess ^^ with 100+ trees wouldnt it make performance worse ?

@Ziden said:
Im not sure, it was a guess ^^ with 100+ trees wouldnt it make performance worse ?

Separate the world into chunks and make an array of trees for each chunk, then when hitting only check for trees in your chunk! :)

If you use the physics engine, the listener is called anyway as far as I know, additional cost is just your listener. Don’t guess at performance, profile and test.



(Also the DBVT approach the physics broadphase use is probably superior to a chunk based approach.)

And i guess trees should have colision anyway, so not really more calculations.

@ivandonat said:
Separate the world into chunks and make an array of trees for each chunk, then when hitting only check for trees in your chunk! :)


i was doing something simillar to this, i was divigind the map in region nodes, witch would be used for collision

but if i implement collision listeners i couldnt limit the collision checks in a range, could i ?

besides that, is it possible to show a ray in screen ? I think im getting my collision ray wrong, hes never httin whats hes suposed to hit.

Cretae a arrow Mesh for the rays, and attach it when you do ar ay, then you see it.

1 Like

Thanks for the attention, its working now !



the trees already have rigid body control



Just a simple question, if i batch geometry together, how can i identify it, since its name will be batch[0] ?



Ive tryed setUserData but its becoming null !



again, thanks for the answers

Do you need to identify the geometry for collision? There should be a way to determine which triangle index in the batch belongs to which geometry. @nehon is there any look up table to accomplish this?

collision test should work as usual.

Sub geoms are still there with all the mesh data, just don’t take the collision results on batch0 into account.

@nehon said:
collision test should work as usual.
Sub geoms are still there with all the mesh data, just don't take the collision results on batch0 into account.


Seems like BatchNode could be modified to avoid this, yes?

The collision aways return me a Batch[0] geometry ;( How could i possibly acess ‘inner’ geometyes ?



Its like



Tree Geometry Bashed > TreesListNode > EntityNode > MapNode



Im colliding with the TreeNode, and each tree has 3 different geometryes.Trees are placed in a ‘treeRootNode’ witch will be batched and placed in the treelistnode.



Couldnt find a way to know when i hit it, since its aways returning meh batch[0] :frowning:



If i rename or try to input data after batching the node it doesnt change



Thanks for thy attention !

@Ziden said:
The collision aways return me a Batch[0] geometry ;( How could i possibly acess 'inner' geometyes ?

Its like

Tree Geometry Bashed > TreesListNode > EntityNode > MapNode

Im colliding with the TreeNode, and each tree has 3 different geometryes.Trees are placed in a 'treeRootNode' witch will be batched and placed in the treelistnode.

Couldnt find a way to know when i hit it, since its aways returning meh batch[0] :(

If i rename or try to input data after batching the node it doesnt change

Thanks for thy attention !


Are you just getting the nearest hit or are you going through all of the hits? You should be getting both the batch[0] hit _and_ the hit for the individual child but the batch[0] node (until nehon has BatchNode override collideWith to skip it) will always be the nearest one.
1 Like

ahh i see thanks alot man



EDIT: When i overriden nodes collision node, this node cant collide no more, and when i list collision inside a batched node, it returns me 2 batch[0] , so still i cant identify the tree.



Thanks for the attention !

@Ziden said:
ahh i see thanks alot man

EDIT: When i overriden nodes collision node, this node cant collide no more, and when i list collision inside a batched node, it returns me 2 batch[0] , so still i cant identify the tree.

Thanks for the attention !


I can't tell how long your piece of string is from here. I'll have to see it. ;)