Are Kinematic bodies what I should use for projectiles?

Hi,

I have been reading the docs about collsions, and I have noticied I need a Rigid body to a collision to be accomplished. Kinematic bodies seems to be the ones that eat less cpu, are they the best options for projectiles? For exampel fireballs, bullets, etc…?

Thanks in advance,
HexDump.

Rigidbodies are required when you want to use physics to move the object. If you want your projectiles to have convincing physical motion, you could do this by adding a rigidbody to the projectile object. In the game, you then launch the object by applying a force, and let the physics engine take over from there.

A kinematic rigidbody is used only in certain specific situations. There are some things handled by the physics engine that need a rigidbody to work, but you don’t always want the object with the rigidbody to have physical behaviour (fall under gravity, etc). In this case, you would make the rigidbody kinematic. Another situation is where you need to take direct control of an object normally handled by the physics engine. Here, you would make it kinematic temporarily and then set it back when you released control again.

If your game is a game of skill where you launch fireballs, etc, attempting to hit targets, then rigidbody/physics objects would work well. If you are just showing the motion of the projectile (for an RPG, say) then you should probably just animate the object directly from the script.

I think it really depends on the situation

I personally use sprite bullets (SM2) and then raycast to check for collisions and it seems to work pretty well (and was recommended to me by the IRC guys) :slight_smile:

Hi!,

Well I just was a bit afraid of rigidbodies killing performance, so, this is why I tried to use the kinematics thing. My projectiles are just a particle system ball, that I move with scriptting towards the enemy, but to have a collision you need allways a rigidbody (don’t you?), this is why I asked.

Thanks in advance,
HexDump.

jbury, I’m using sprite bullets as well, i’m curious do you raycast from each sprite, or from whatever launched the projectile?

If you have a projectile on a frame at positionA, then positionA + velocity = positionB.
positionB - positionA is your vector to check for collisions, for that projectile, on that frame.

so use the Raycast which has the out RaycastHit. The parameters of the Raycast would be
origin: positionA
direction: positionB - positionA (the vector from A to B)
distance: the magnitude of the vector from A to B

if Raycast returns true then use the hitinfo you passed in to get the details (RaycastHit.point, RaycastHit.collider, etc)