My gun currently just drops a bullet on the location I aim at. I want it to fling the bullet at the target and bounce off. Because it just drops it on the location, it takes the HP of the enemy within 3 shots ![:joy: :joy:](https://emoji.discourse-cdn.com/win10/joy.png?v=9)
I tried learning about impulses and I tried to apply it to my code, but I get errors that I can’t solve and solving them would bring more issues for me.
Any ideas on what to do?
Is this following on from this question?
If you could share the errors or even better a playground example that would be great.
That being said if you want the bullets to bounce off the enemy look into increasing their restitution.
https://playground.babylonjs.com/#A2LQK1
Yeah, it’s following on from that question (should I just reply my next questions for the same topic instead of making a new question?)
If I try using impulses, it’ll say “ImpulseVector not defined”
let localRefPoint = new BABYLON.Vector3(1, 1, 0);
bullet.applyImpulse(ImpulseVector, bullet.getAbsolutePosition().add(localRefPoint));
Increasing restitution did help a bit, but sometimes it just drains HP or doesn’t even touch the player.
I think creating a new question is fine, I just found it interesting I was just finishing up reading your previous question and this one showed up ![:grin: :grin:](https://emoji.discourse-cdn.com/win10/grin.png?v=9)
Well from the code you’ve share ImpulseVector
is indeed not defined. The first argument to applyImpulse
has to be a Vector3.
Another option that may remove the need for this would be to add a flag to your bullet object. I’m not sure how you’re code is structured but you could add a disabled
variable to your bullet class and after a frame of colliding with the enemy set it to true
. When you do your damage/HP checks then check whether the bullet is disabled or not. If it is disabled then simply skip the code that removes HP.
1 Like