About CollisionSpace How to use

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?

There are 2 ways to use CollisionSpace:

  1. Instantiate it directly, using the constructor.
  2. 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:

GhostControl gc = (GhostControl) collisionObject;
Spatial spatial = gc.getSpatial();
1 Like

Thank you for your reply.
Dig deeper into the documentation I found Physics Collision Listener This is what I want :wink:

I noticed that the Physics Collision Listener for the Minie seems to be different from the one for the bullet

Minie Specifies whether the demo that uses ContactListener and PhysicsCollisionListener exists

(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)

On ghost objects, you can also use getOverlappingObjects() to retrieve a list of objects that currently are overlapping with ghost.

See this example:

1 Like

First of all, thank you

        if(ghostControl.getOverlappingObjects()!=null){
         for(int i=0;i<ghostControl.getOverlappingObjects().size();i++){
         if(ghostControl.getOverlappingObjects().get(i).equals(DummyRole.ghostControl)){
         System.err.println("Collision detected"); 
         }
         }
         }

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 ()

Another question is how do I get the detailed coordinates of the collision where I might need to show the attack trace where it was hit

Then use the PhysicsCollisionListener.

Also, note this:

You can get that info from PhysicsCollisionEvent

1 Like

I don’t understand what you mean

  • 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
    }

image

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?)

Try enabling Continuous collision detection for ghost and see if it fix:

ghostControl.setCcdMotionThreshold(0.01f);

More info: An introduction to rigid-body physics :: The Minie project

1 Like

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 :pensive:

    @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

Not sure why it can not detect all hits. Maybe @sgold has an idea.

Try to call enableGhostCollision in your animation a few seconds earlier and see if it makes any difference.

1 Like

In regards to this question:

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.

1 Like

Also, noticed the target collider is half in the ground. Move it up and try again.

1 Like


They hit only 5 out of 10 times

Thanks for your help I will try :slight_smile:

hello,sgold,
Could you give me some suggestions :wink: :thinking: :thinking:


I’m happy to tell you that after adjustment, the collision reached a very high accuracy

  • The value of setCcdMotionThreshold() has been adjusted.
  • The width of the ghost body has been adjusted .
  • Dummy ghost body also added setCcdMotionThreshold().
  • Changed the number of frames for adding and removing ghosts
    But in the relative limit distance sometimes you collide and sometimes you don't
ghostControl.setCcdMotionThreshold(0.000000000001f);

I didn’t realize that setting parameters like this would work.
That’s a lot of zeros :joy: :joy: :joy:
Thank you very much for your help :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: :smiling_face_with_three_hearts:

1 Like

Continuous collision detection is only for rigid bodies. It shouldn’t have any effect on a GhostControl.

1 Like

Use a sweep test instead of a GhostControl.

1 Like

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

1 Like

Probably this should be documented in Javadoc or wiki.

2 Likes