[solved] Shooting bullets to different mouse-click positions

Hi,
I shoot bullets to the position of my mouse click and when the bullet arrives at this position it disappears.

I tried two solutions:

  1. Creating a point at the mouse position with which the bullet collides and disappears - this works well most of the time, but if I click, for instance, two times and the second click position is in the same angle just below the position of the first click, the first bullet will travel to the position of the second click instead of the first one.

  2. Storing the x and y position of the mouse as a variable - this seems to be the more elegant solution but here I am facing the problem that as soon as the clicks are in the same angle, all bullets will disappear at the last click-position before arriving at their actual target-position.

I guess the problem I am facing is the same for both solutions: the initial value of the variable is overwritten by the next value. So how can I make sure that the position is stored as long as the bullet is travelling and other click positions for the following bullets are also stored?

The basic structure of my events for storing the mouse x and Y position is here (the target_position object is just created for me to have a visual reference to the position):

The scene itself consists of nothing else than the turret at the bottom:

Any suggestion how I can solve this problem is highly appreciated.

You are pretty close to what I’d suggest, but I’d tweak slightly with this:

Upon creating your bullet(actions immediately following the create action), store the mouse x/y location as an object variable *on the bullet iself".

Each bullet will then have unique destination object variables.

Then you just do a for each bullet event, and have it go towards the destinations stored as object variables.

You never update the object variables past the creation point, so they should keep static values.

Scene variables will update each time you run the events, which is why you are experiencing your current situation.

Make sure the movement event is separate from any other events, too. It shouldn’t be a sub event.

5 Likes

Yes, that’s it. Thanks a lot!!!