Correct approach to create multiple projectiles with no gravity or force

Hi everyone, me again. I’m trying to create a bullet hell minigame and I’m working on the player projectiles, specifically on the projectiles’ collisions. I’m trying to create a projectile collision with no forces caused, this means the projectile hits the target, the projectile disappears and the enemy takes damage. I’m not sure how to create these collisions between the enemy meshes and the projectiles, both of them are imported meshes. Here is what I tried so far:

  • Assign enemyMesh.checkCollisions = true, where “enemyMesh” is the __root__ mesh of my enemy, doesn’t work. The collision is not detected.

  • Using Havok: Assigning aggregates to both, enemy and projectile, works only when both bodies have mass, the problem here is the projectile travels using projectileMesh.physicsBody?.setLinearVelocity, this ends up causing a force on the enemy, moving it. (If you have a better suggestion to shoot the projectile, I’d love to hear it too)

I know is a lot, so feel free to take a look at the repo: GitHub - ElHurta/hacking-automata.


I don’t think using Havok for a Bullet Hell game is a good match.
2D AABB rectangle test code is small and looks like :

function doRectanglesIntersect(rect1, rect2) {
    return rect1.x < rect2.x + rect2.width &&
           rect1.x + rect1.width > rect2.x &&
           rect1.y < rect2.y + rect2.height &&
           rect1.y + rect1.height > rect2.y;

If it’s 2D, I would defintely go with something small like that.

That makes it a lot easier. Question, how would you shoot the projectiles without using the linear velocity? I came up with that but I know is not a great solution.
Thanks for the suggestion!

no linear velocity = not moving

You need a velocity.

I mean, without using Havok :sweat_smile:. Sorry for the misunderstanding

you can find some 2d tutorial over the web quite easily.
at the end, it will look like:

position.x += velocity.x * deltaTime;
position.y += velocity.y * deltaTime;

Wonderful, thanks a lot!

1 Like