How do I set the bullet angle of motion to a touch?

0 favourites
  • 10 posts
From the Asset Store
Complete the collection by purchasing Motion Universe Pt. 2
  • I'm creating a game where the player (blue ball) has to dodge the red balls for as long as possible. The player can also shoot the red balls to destroy them but how do I set the angle of motion of the bullet to the correct touch?

    The player moves using drag and drop behaviour, so is already touching and to shoot the enemies they tap them. However, when I set the angle of motion to Touch.X and Touch.Y, it's using the X and Y of the player and not the second tap.


  • Check out the documentation, there are a few expressions you can use when dealing with multitouch.

    Try setting the angle to:

    angle(Player.x, Player.y, Touch.XAt(1), Touch.YAt(1))

    where "1" is the index of the second touch (zero-based).

  • That works - cheers Dop! Much appreciated.

  • Hi Dop, sorry to message again but I'm wondering if you can help with something else.

    In the game, I want the player to get power-ups such as the ability to shoot the red balls, invincibility etc. The player gets a power-up for 10 secs when they collide with a gold ball and I'm using instance variables to do this and also having to use a different gold ball for each power up, and it feels very messy as I'm having to create a lot of events.

    Is there a way I can use one gold ball and randomise which power-up the player gets when they collide with it?

    Is instance variables the best way to go about doing this? I'm not 100% sure it is.

    Let me know what you would do.

    Thanks again.

  • I would definitely use one sprite for all powerups. You can set powerup type with an instance variable, or use different animations, or animations frames.

    For example:

    Player on collision with PowerUp
     PowerUp is playing "Invincibility" animation : Player set isInvinvible=true
     PowerUp is playing "Health" animation : Player add 1 to HP
  • Thanks Dop, this makes sense. I think I can use a global variable number, randomise this on collision with the gold ball and each number will correspond to a different power-up.

    One last thing, I want the gold ball to appear to be shot into the screen and ping around in various directions randomly before being destroyed after 10 secs if the player hasn't collided with it. How would I go about doing this? All my attempts so far have failed.


  • You can use Bullet behavior with bounce off solids enabled. Also Fade behavior to automatically destroy it after 10 seconds.

  • I have used the bullet behaviour, set to bounce off solids and set bound to layout. This makes the ball fly into the layout but after a few secs it falls to the bottom of the screen and sits there until it's destroyed.

    How do I keep it flying around the screen randomly for the full 10 secs?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Make a solid border for it. Also make sure there are no other behaviors. Bullet should not fall down and stop, you probably added Physics to it or something like that.

  • Thanks a lot Dop - the solid border worked! Really appreciate your help :)

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