Bullet changes direction mid air

0 favourites
  • 14 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • Hi everyone, I am making a police video game and basically I have bullets firing and the character has 8 direction enabled. So I need the bullet to change angle where the character moves, so I set the angles like this. when keyboard key left is down, set bullet angle to 180 degrees. I have done this for 8 different directions. But the problem is that the bullet changes mid flight when the character changes direction. Any thoughts?

  • You should set the angle of the bullet as it is spawned. Since you already have the key events you could set a variable to a value, and then on spawning the bullet, depending on the value set it will set that direction.

  • Also you should have your bullet image in a strict angle. Will be easier to control.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Could you show me n example

  • Just do the following :

    Add a global variable

    Under the set bullet to angle degrees actions, add a different action 'set variable to X degrees' where X is the value you have for the bullet angle.

    Delete the set bullet angle actions.

    On the spawn/click event, add an action below spawn bullet : set bullet angle to 'global variable' degrees

  • Better use instance variable tho. Bad habit using global variables for everything.

  • Better use instance variable tho. Bad habit using global variables for everything.

    The variable is used to detect the shooting direction of the player, anything player related I use global variables because it's just easier to avoid bugs. The bullet then takes its angle directly from the player's shooting angle stat.

  • I don't understand how anything that simple could cause bugs. In a bigger project, if you approach your coding like this it will turn into a mess of variables spread around event sheet.

    There is also no need to transfer that data between levels (this is what global variables are normally used for) as it is just inputs and if you use getter function you can do it all even better.

  • I don't understand how anything that simple could cause bugs. In a bigger project, if you approach your coding like this it will turn into a mess of variables spread around event sheet.

    There is also no need to transfer that data between levels (this is what global variables are normally used for) as it is just inputs and if you use getter function you can do it all even better.

    Usually player related things are used globally throughout the game so as a standard I use global variables for anything player related. Whether I'm using global or instance variables it is kind of irrelevant though as the events are the same, it is just a preference.

  • I tried it and I think this is what you meant but it still changes direction. just letting you know that my character has 8 direction enabled but here is the event sheet.

  • dont set bullet angle when keys are pressed on the keyboard. That will affect all bullets (and make them change direction).

    set the global variable to know which way NEW bullets shoot, but only set the bullet angle when you spawn the new bullet - it will be the only one selected at that time, so other bullets wont change direction.

  • Not quite what I described but almost there. You should only have one set bullet angle action, on spawning the bullet with the mouse click event. Delete the rest of them!

  • I have another question, I am making a police game and I need the final level to be done but I am so confused since I am pretty new to this. I need to make an npc follow the main character and shoot bullets at the main character the whole time. So how to I make the NPC follow and attack? my character uses the 8 direction tool just to give some background info

  • Have a look at Pathfinding behaviour

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)