Sign in to follow this  
IndieDev0815

How to implement a bullet shell ejection system?

Recommended Posts

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:
https://m.youtube.com/watch?v=qGboxgcSvxc

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this