Hei guys!
I’ve tried around a bit and now I want to write some small test programs.
Now I would like to know from you whether there is a function that returns TRUE or FALSE
when two objects touch or overlap.
I hope you can help me!
THX…
schnacko
You need a CollisionListener:
[java]
package mygame;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
public class MyCustomControl extends RigidBodyControl implements PhysicsCollisionListener{
public void collision(PhysicsCollisionEvent event) {
try{
System.out.println(event.getNodeA().getName() + " " + event.getNodeB().getName());
} catch (NullPointerException e){
}
}
public MyCustomControl(BulletAppState bulletAppState) {
bulletAppState.getPhysicsSpace().addCollisionListener(this);
}
} [/java]
And from the Main or where you will use it:
[java]MyCustomControl m = new MyCustomControl(bulletAppState);[/java]
It will output automatically - just like an AppState.
Credit must go to whoever first gave this code to me.
Thank you for your fast reply…
But what should i do with the >m< Objekt now?
m.collision and what… i don’t understand what you are doing with this methode…
schnacko
Oh sorry. This method works when you have two or more Physics Objects. For example, you have two RigidBodyControls and you need to check when they collide.
okay…
isn’t there a function: boolean checkCollision(Spatial object1,Spatial object2); or like that?
Dude, theres a manual :roll:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:collision_and_intersection
That’s what I use… Never seen that normen. Thanks.
Thank you … i will try it out tomorrw… when i get problems i will tell
schnacko
@normen, sorry to hijack the thread. What would you recommend in an RPG where you need to check collisions? I think my method is called just like an AppState. On the other hand, I think that to check for collisions using the code in that link you would have to flood the update. Would I be better off to use Physics and use non-physical when collision detection is checked every frame?
@memonick said:
Would I be better off to use Physics and use non-physical when collision detection is checked every frame?
Mixing both systems is suboptimal, no.
So Physics would be good in an RPG?
I meant - using RigidBodyControls and CharacterControls, then using the code I gave to the original poster to detect collisions.
It depends :roll:
Hmm… I’ll get more advice once I advance more in the game. Thanks anyway
I need help…
My code is here:
http://pastebin.com/sPEwn7YQ
But there is a fail!..
I don’t know what i have to do…
schnacko
You will not get help.
Because we don’t know what the problem is.
If you want to Get Answers, read this.
sorry i try it again…
I tried out the code sample from the link norman gave me…
Yuo can see my code here: CollisionTest.java
When i run it I get this error:
it says to me on line 65 is a Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.collision.UnsupportedCollisionException
In the end I want to set a new position of node2 when node1 collide this…
so is it better this way?
schnacko
have I forgotten something?
I am new at JME3 and new at this Forum so… when i make mistakes please tell me…
schnacko
I don’t know enough about the subject of your question to help. You need to show the FULL exception (stack trace etc) though.
Have you tried googling the error message and/or looking at the source where the exception was thrown to see if that is helpful.