How to set random angle + constant?

0 favourites
  • 5 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Sorry for the noob question, but I couldn't find the answer by searching and it's driving me crazy.

    Also, it might be something else incorrect that I'm doing because this seems too basic not to work.

    Basically, I want to set spawning sprites' angle towards the current mouse position, but with some random noise. I'm trying to spawn bullets towards the player, but not exactly at the player. (I want some "spread")

    I'm using:

    Set angle toward function with a value of:

    X = mouse.X + random(45)

    Y = mouse.Y + random(45)

    However, when I try running my game, it doesn't add anything random. It's treating it like the "+ random(45)" isn't there. If I take away the mouse.X and mouse.Y terms, whenever something is spawned, it's always at the same angle, like it's not creating a random angle. Strangely, it seems that each instance of the spawning sprite is offset by 45 degrees more than the last.

    What am I doing wrong??

    (First post, if I can somehow post my code, please yell at me and tell me to do so, but... I don't know how...)

  • hmmm i think the problem in the condition or the action before it. try this:


         condition : on mouse clicked

         action1 : enemy spawn bullet

         action2 : set angle (mouse.x + randome(45), mouse.y+random(45))

    also to check if that random function work or no try to use this:


         condition : on mouse clicked

         action1 : enemy spawn bullet

         condition2:system everytick:

         action2 : set angle (mouse.x + randome(45), mouse.y+random(45))

    you will see that the angle keep changing while the bullet moving

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • you could do a

    -> enemy: spawn bullet

    -> bullet: set angle toward mouse.X,mouse.Y"

    -> bullet: set angle to angle+random(-10,10)

  • yeah like Yann said. Set it first then add random. Do do both at the same time

  • Nice! Setting the angle first and then adding a rotate with a random angle works like a charm!

    Thanks for the help!

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