Top Down "Physics" for Bullets

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StrikerSVX

Hello, Striker again, i’m making progress in my game and more doubts began to appear on how do i make some things, from there i do some research just so i don’t ask something that has already been asked before, but with no clear answer to my question i need to ask: how do i stop my bullet? weird because on a top down game you wouldn’t need to stop your bullets, but to the logic of my game the player should be able to point and shoot, and the bullet should stop where the player shot (like if it feel on the floor, just like physics would work), i attempted to write some script but no success yet, so “how do i stop my bullet?” (just to remember this is for a top down game!)

:bust_in_silhouette: Reply From: TheFamousRat

I think you are making it kind of complicated. I think that using a RayCast from the gun to check if something was hit, and a particle for the bullet body would work very well.

However if you want realistic bullet behaviour, I see two possibilities. Both use PhysicsBody and work in either 2d or 3d :
Note : I use the names of the 3d nodes, the 2d nodes have the same names with ‘2d’ attached to the end

  1. Use a RigidBody for the bullet. That’s it really, when the gun shoots create a bullet instance in front of the gun, give it velocity with apply_central_impulse and it will collide and react correctly. It however also is affected by gravity, so this might be a tad too realistic
  2. Use a KinematicBody. The KinematicBody node allows you to move a physics object however you want in the physics_process method. With the test_move method, you can check whether the body is colliding with something. When that is the case, react accordingly (delete the bullet, apply gravity to it etc…)

Those two solutions could answer your question. I however would advise against them, and direct you towards the RayCast solution : this is a case where too much physics could ruin the gameplay, except if it is a core/fun gameplay element.

Hope it helped,

i like the idea of raycasting, and i probably could find a way to get the mouse position and translate that to be the limit to where the bullet goes. Thanks for the help.

StrikerSVX | 2020-09-12 14:22