16
$\begingroup$

I am currently trying to make a tank to work in the game engine. I have the body roughly done and am trying to get the gun to work. Just making the barrel create a shell at a high velocity doesn't work because the shell travels to fast for the engine to detect a collision. If I have the velocity down enough that the collision is detected, the shell doesn't really have enough speed.

Are there any other ways to make a shell behave like a bullet and still detect collisions? I've tried making the bullet larger, but that still doesn't always collide.

$\endgroup$
16
$\begingroup$

In the physics tab turn up the Physics Steps > Substeps. This will calculate physics in between frames.

$\endgroup$
  • $\begingroup$ Am I missing something really obvious? I can't find the Physics Steps option. I saw it just the the other day... i.stack.imgur.com/Cb5eG.png $\endgroup$ – American Luke May 25 '13 at 1:04
  • $\begingroup$ Never mind that, I found it. Just looking the wrong place. This works, thanks. $\endgroup$ – American Luke May 25 '13 at 1:22
  • 2
    $\begingroup$ Shouldn't that slow down the calculation time significantly? I don't know how physics intensive the OP's game is, but that might cause it to lag. $\endgroup$ – Gwen May 25 '13 at 1:33
  • $\begingroup$ @Gwenn turing it up to 4 might, but having it at 1 or 2 should not effect performance greatly. $\endgroup$ – CharlesL May 25 '13 at 11:36
  • $\begingroup$ @Gwenn Right now the game is really rough. The models are kinda boxy and the colors are just slapped on. I don't know how it'll function in the final version, but right now it's doing pretty good even when I turn it up to 4. $\endgroup$ – American Luke May 25 '13 at 14:45
8
$\begingroup$

Another option is to use a raycast sensor in front of the bullet object is probably the most performant and reliable solution. The ray length should be longer than the distance the bullet travels per physics frame (which should be 60hz, assuming you are not using physics substep).

$\endgroup$
6
$\begingroup$

The problem is that your bullet shell is traveling so fast that it goes clear through the target object between frames.

One option use can use to solve this is to simultaneously create your bullet shell and an empty shell that is longer than the original bullet and aligned with it. The player will only see the visible bullet shell, but you can use the invisible one to calculate collisions. Even if the visible bullet passes through an object between frames, the invisible one won't, which allows you to still catch the collision.

$\endgroup$
  • $\begingroup$ I've tried that, but it still doesn't always catch it. It also can make the physics of the impact look qwerky when it does catch it. $\endgroup$ – American Luke May 25 '13 at 14:43
  • $\begingroup$ @Luke If you decide to go the empty-bullet route, you could solve the strange physics problems by instead using a string of overlapping individual empty bullets. CharlesL's solution sounds cleaner overall, but if you encounter lag, it might be nice to have another option like this handy. $\endgroup$ – Gwen May 27 '13 at 2:05
  • $\begingroup$ Alright. I'll consider switching to this method if it starts lagging as I work on it. Thanks $\endgroup$ – American Luke May 27 '13 at 16:38
0
$\begingroup$

maybe try using the near sensor to activate your logic when your bullet is within a specified distance from your target? Since it is a distance parameter rather than a collision parameter, it may behave differently. I haven't tested it but it might be worth trying.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.