I need to listen for ghost body collisions.
I flip through Minie API Class CollisionSpace appears to be used to detect collisions.
If I’m wrong about CollisionSpace Please tell me which class detects ghost body collision.
If I am correct, please tell me how to use CollisionSpace. I can’t find a way to use CollisionSpace in the source code
Two ghost body can be seen
I need to know which one the weapon hit ghost body.
Whether the ghost body can be set with an ID to associate with the model?
Create a PhysicsSpace using BulletAppState in the usual manner. PhysicsSpace is a subclass of CollisionSpace; it exposes the entire CollisionSpace API.
For real-time, physics-oriented games, I recommend #2.
To associate application-specific information with a PhysicsGhostObject, you could use the setApplicationData() method. However, I believe this is rarely done because most people create a GhostControl.
If you use a GhostControl, it already has a reference to the model, which you can access using getSpatial(). Hence:
(The translator I’m using seems to have trouble translating statements into tense)
(If you have any questions about my question, please point them out)
I wrote down a basic collision call logically but I found that they would trigger many times and I only had to decide to trigger once
This code is run in update ()
My attack judgement produces multiple collisions but only want to settle the damage once
But I tried PhysicsCollisionListener The following problems are found
public void enableGhostCollision(){
SkinningControl modelSkinningControl = ((Node)modelSyana.model).getChild(0).getControl(SkinningControl.class);
modelSkinningControl.getAttachmentsNode("Bone023").addControl(ghostControl);
modelSyana.bulletAppState.getPhysicsSpace().add(modelSyana.ghostControl);
modelSyana.bulletAppState.getPhysicsSpace().addCollisionListener(this);
}
public void disableGhostCollision(){
SkinningControl modelSkinningControl = ((Node)modelSyana.model).getChild(0).getControl(SkinningControl.class);
modelSkinningControl.getAttachmentsNode("Bone023").removeControl(ghostControl);
modelSyana.bulletAppState.getPhysicsSpace().removeCollisionListener(this);
modelSyana.bulletAppState.getPhysicsSpace().remove(modelSyana.ghostControl);
}
@Override
public void collision(PhysicsCollisionEvent event) {
System.err.println(event.getNodeA()+","+"A");
System.err.println(event.getNodeB()+","+"B");
//throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
If I attack from the same distance, I get different results
If the animation is fast Sometimes attacks go undetected
As you can see from the picture, I attacked the two collisions and the results were different Sometimes multiple results are returned and sometimes one is returned.
When I slow down the animation it becomes much normal.(Is this normal?)
void
You can see it in the video I made 10 attacks hit the 7
sometimes hit the 3 to 5
The result is far from the expected hit
@Override
public void collision(PhysicsCollisionEvent event) {
if ( event.getNodeA().getName().equals("NodeDummy")&& event.getNodeB().getName().equals("Bone023_attachnode")) {
System.err.println("collision");collision++;
} else if ( event.getNodeA().getName().equals("Bone023_attachnode")&& event.getNodeB().getName().equals("NodeDummy")) {
System.err.println("collision");collision++;
}
}
public void enableGhostCollision(){
SkinningControl modelSkinningControl = ((Node)modelSyana.model).getChild(0).getControl(SkinningControl.class);
modelSkinningControl.getAttachmentsNode("Bone023").addControl(ghostControl);
ghostControl.setCcdMotionThreshold(0.01f);
modelSyana.bulletAppState.getPhysicsSpace().add(modelSyana.ghostControl);
//modelSyana.bulletAppState.getPhysicsSpace().addCollisionListener(this);
}
This is code that detects collisions .
My examination seems to have found nothing wrong.
I guess it was the physics engine but I don’t know if it was my misunderstanding of the physics engine or the physics engine itself
You can solve this by keeping a list to track the people that have already been hit by a swing attack so that damage will only happen on the very first collision.
Whenever a hit is detected, check to see if the person is already stored in the list.
If they are not already contained in the list, do damage and add them to the list so they won’t be damaged again on the next collision.
Here’s some simplified example code to explain better:
public ArrayList<Agent> damagedAgents = new ArrayList();
public void collisionHappened(Agent collidedAgent){
if(!damagedAgents .contains(collidedAgent)){
collidedAgent.takeDamage(damage);
damagedAgents .add(collidedAgent);
}
}
And then you would also need to clear the old list at the start of each new swing motion to allow previously damaged people to be damaged again.
I guess I misunderstood again
Maybe it’s the adjustment of other parameters
I’ll run some tests.
I’ll check out the documentation on Sweep Test
Thanks for the tip