[SOLVED] Bullet's aren't working

        var entity = this.app.root.findByName("bullet").clone();
        this.entity.addChild(entity);
        entity.enabled = true;
        this.entity.findByName("entity").rigidbody.applyForce(0, 10, 0);

this is the code i am using to clone my template bullet in my fps game. it is fired when i click ‘e’. (i need to change it to the lmb). It’s not working and i can’t figure out why. I would appreciate the help i can get.

https://playcanvas.com/project/1027777/overview/idk-at-this-point

Hi @almish_subuk!

Maybe you can try to replace line 2 with:

this.app.root.addChild(entity);

And line 4 with:

entity.rigidbody.applyForce(0, 10, 0);

You can also try to replace applyForce with applyImpulse. Make sure the rigidbody is dynamic.

https://playcanvas.com/project/1027777/overview/idk-at-this-point
Another issue has popped up in my game. I have added a red guy (enemy) to the game, but the collision doesn’t seem to be working properly. When I crash into the enemy with the player, it moves around and can be pushed, but when i shoot the gun, the bullets only rarely hit the red guy. Usually they just go through him. Can anyone take a look at my project and show me the issue?

I think the problem here is that the enemy has a dynamic rigidbody. If you move an entity directly instead of using forces on the rigidbody, the visual entity is moving while the rigidbody stays at the same place. I suggest to use a kinematic rigidbody for your enemy entities.

https://developer.playcanvas.com/en/user-manual/physics/physics-basics/

https://developer.playcanvas.com/en/tutorials/Using-forces-on-rigid-bodies/

2 Likes

thanks for all the help. I have figured out the problem, and added a solution. Thanks for helping me out and being cool.

1 Like