Wierd Projectile firing bug

For the life of me i cant seem to figure out why my game has stopped firing projectiles after i spawn in an enemy,



code of projectile:

[java]

public PhysicsProjectile(float ttl, String name, Spatial model, RigidBodyControl control, Player player, Physics physics, Vector3f target){

this.ttl = ttl;

this.physics = physics;

this.model = model;

this.control = control;

this.node = player.getNode();

time =0;

this.name = name;

active = true;

model.setLocalTranslation(player.getNode().getLocalTranslation());

control.setCollisionGroup(player.getControl().getCollisionGroup());

control.setCollideWithGroups(player.getControl().getCollideWithGroups());

physics.AttachToBAP(control);

control.setGravity(Vector3f.ZERO);

model.addControl(control);

node.attachChild(model);

physics.getBAP().getPhysicsSpace().addCollisionListener(this);

control.setLinearVelocity(target.mult(40));

}

[/java]



the enemy is another instance of my mainplayer but using an enemy boolean i set the enemies to a different collisiongroup, (enemies also use charactercontrol)



the code that creates the projectile, in print outs, it shows it has a target and that its attached to the node but for some reason its not showing in the game once an enemy has been spawned



[java] physics.addProjectile(new PhysicsProjectile(6, "SnowBall", new Snow(assetManager, null), new RigidBodyControl(new SphereCollisionShape(1f), 1f), player, physics, target));

[/java]



Thanks,

I narrowed down the problem to collision groups,

for some reason the main player(person you control) whos been set the following (!enemy):



[java]

if(enemy){

control.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02);

control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);

}else{

control.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01);

control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);

}

[/java]



fires the projectile correctly, i.e. it comes out from his center and heads in intended direction,



however when the enemy fires, even though the projectile uses the same collision group as the enemy, either gets stuck inside the enemy capsule or is super speed fired in an upward direction.

what could be causing that ?

From the jme3 javadoc “Two objects will collide when one of the partys has the collisionGroup of the other in its collideWithGroups set.”

Your projectile set-up seems okay. I think the problem may lie in the creation of your enemy - if you are not changing the enemy collideWithGroup from the default then that would explain the behavior you are seeing with enemies firing in such an odd way. But if your previous post was your character initialization, then I am clueless -_-

i figured out the problem, apologies for not putting solved in title,

problem was when i set a target vector, the main players target was camera direction where as enemy target’s were player location, so i had to normalise vectors so they fired at the same speed, problem was it fired so quickly i couldnt see it.