How to implement a bullet shell ejection system?

Started by
1 comment, last by IndieDev0815 7 years, 4 months ago
Hey guys,

So at the moment i am working on a 2d top down shooter, kind of like hotline miami and i was wondering on how to implement a bullet case ejection system so that the bullets fly off the gun and drop to the ground.
I am working with java/slick2d and can't wrap my head around how to implement this.
I already read about working with sinus and cosinus but that didnt do the trick for me. I am also working with rotations and want to align the bullet shells with the rotation of my player AND manipulate the direction so that a bullet can fly in a general direction and randomize its path on the ejection.

I really hope that somebody can help me.

Thanks in advance!

I want the shells to fly like this:
Advertisement

Are you using something like Box2D for the physics? It'll be easier if you use a physics engine. You can get a side vector by making a cross product from the "forward" vector of your character and some other fixed vector (since its 2D you can remove a few terms, its easy once you have the function written).

Then you add tiny short lived cylinder coliders, that collide with all the solid stuff but that you cant collide with. You can handle that with collision masks.

I guess the point of expulsion would be the center of the character + some arbitrary length along the forward vector. From there, they'd get expelled in the direction of the side vector you got before.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

No, i am not working with Box2D. It's for a project and we are only allowed to work with slick2D alone. I don't quite know how to realize what you decribed. I think i would understand better in code. But you kind of described what i had in mind.

This topic is closed to new replies.

Advertisement