Battle Ship 3D game – Error

hello, I want to know what does this error means ?

com.jme3.scene.Geometry cannot be cast to com.jme3.scene.Node

Thanks in advance :slight_smile:

this error appears here:

[java]Spatial enemy_1;
CompoundCollisionShape compoundShape = new CompoundCollisionShape();
BoxCollisionShape BCS = new BoxCollisionShape(new Vector3f(4f, 4f, 4f));
compoundShape.addChildShape(BCS, new Vector3f(0, 1, 0));
Enemy_1_Node = new Node(“Enemy_1_Node”);
enemy_1 = (Node)assetManager.loadModel(“Models/Boat Fishing 01/boat_fishing_01.obj”);
enemy_1.setShadowMode(RenderQueue.ShadowMode.Cast);
enemy_1.setLocalTranslation(-500.0f, 115.0f, 200.0f);
mainScene.attachChild(enemy_1);
Enemy_1_phy = new RigidBodyControl(10f);
enemy_1.addControl(Enemy_1_phy);
bulletAppState.getPhysicsSpace().add(Enemy_1_phy);[/java]

It means you’re trying to fit a square peg in a round hole.

line 6. The loader seems to return a Geometry and you try to cast it to Node. Just remove the cast, you don’t need it, you’re only using methods that are member of Spatial.

@nehon Thanks for your response :slight_smile:
but I was trying to cast it to a node because collision is not applied on the model :frowning: Don’t know why.
do you have any idea why it is not working? Is the type .Obj is the cause of the problem ? :slight_smile:

@Maha said: @nehon Thanks for your response :) but I was trying to cast it to a node because collision is not applied on the model :( Don't know why. do you have any idea why it is not working? Is the type .Obj is the cause of the problem ? :)

What you cast something to will make no difference in how it functions. If you can call the method on Spatial then the same code gets called if you cast it to Geometry or Node first. Basic OOP.

Thanks @pspeed :slight_smile:
do you know why collision is not working i want the model to be collidable

[java]
private BulletAppState bulletAppState;
private RigidBodyControl Ship_phy;
Ship = assetManager.loadModel(“Models/tall-ship-sailboat-clipper-f/ship_boat.j3o”);
Ship.scale(1.3f, 1.3f, 1.3f);
Ship.rotate(0f, 1f, 0.0f);
Ship.setLocalTranslation(-380.0f, 88.0f, 0.0f);

    shipNode = new Node("shipNode");
    shipNode.attachChild(Ship);
    mainScene.attachChild(shipNode);

    CollisionShape sceneShape =
    CollisionShapeFactory.createMeshShape((Node) Ship);
    mainScene.attachChild(Ship);
    Ship_phy = new RigidBodyControl(sceneShape,0f);
    Ship.addControl(Ship_phy);
    Ship_phy.setGravity(new Vector3f(0f, 0f, 0f)); // no gravity effects
    Ship_phy.setLinearVelocity(new Vector3f(100f, 100f, 100f));
    bulletAppState.getPhysicsSpace().add(Ship);

[/java]

what’s wrong here?
i declared bullet application state, rigitBodyControl and applied it on the ship (model) and applied the bulletappState. where is the error :frowning:

I’ve never used bullet, so I don’t know.

P.S.: You will make experienced Java developers less queasy if you stop capitalizing your variables like class names. This makes my brain hurt:
Ship = assetManager.loadModel(“Models/tall-ship-sailboat-clipper-f/ship_boat.j3o”);

http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html

It really does help people read your code…

Try adding “Ship_phy” to the physics space instead of “Ship”

Mesh/mesh collisions aren’t supported and you are trying to move a RigidBody with a mass of 0 which is meant for static meshes

Thank you all for your help. It is now resolved :smiley: