Bumper class


I’m trying to create a class for a bumper (like in flippers). So I made my class “implements PhysicsCollisionListener” and I started to implement the “collision” method.

Then I want, when my bumper is hurt by another object, this object being applied an impulse away from the bumper (not sure I’m clear). The problem is that with “event.getObjectA().get…” I can’t reach the RigidBodyControl of the impacter. And as the “applyImpulse()” can only be applied to a RigidBodyControl item, I’m kinda screwed ^_^’.

Do you guys have a solution to do this ?

NB: I also tried to reverse the problem by checking the collision from the impacter but for some unknown reasons it didn’t work neither. Maybe cause my object isn’t kinetic I don’t really know.

Either use collisionEvent.getSpatialA() (reading the javadoc would have helped here maybe) or do rigidBody.getUserObject() which will give you the spatial its attached to.

I must have misexplained myself… I know how to get the spatial (or even the CollisionShape) but what I don’t know is how to get the RigidBody attached to this spatial (from inside the collision method).

When i do “event.getNodeA().get…” or “event.getObjectA().get…” eclipse is showing me all the getters I have access to but none is the one I want.

What I’d like to have is something like this “event.getNodeA().getRigidBodyControl().applyImpulse(…);”. But it seems it’s not possible :(.

setUserObject() and getUserObject() are the keywords. I use them myself and it works like a charm for me.

This doesn’t allow me to access to the applyImpulse method. Like I said above, I need to reach the RigidBodyControl and none of the methods I have access to is returning a RigidBodyControl. So what I look for is a tip to do what I want getting around the getters.

I guess this shoudl work:


Nope I tried it already.

But my problem is solved… I’ve managed to implement the collision in my ball rather than in my bumper. This way I have directly access to my RigidBodyControl.

… you can cast objects to their real class, you know that right?

[java]Object object = rigidBody.getUserObject()

Spatial spatial = (Spatial) object;[/java]

Yeah I know and I tried to but I must have been doing something wrong 'cause it didn’t work. But anyway I found another way so… thx !

Sounds like you are doing things completely wrong. Your “bumper” would be a Control and as @anthyon said, when a Spatial has a physics control you can access it with spatial.getControl(RigidBodyControl.class).doStuff()

I think it the same either I implement the collider or the collided. I might even think that’s it would be more optimized to implement the collider as I can have several collided objects in my level while I’ll only have a single collider (my ball).