# How to set random angle + constant?

Get help using Construct 2

### » Tue Jul 17, 2012 9:04 am

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...)
B
2
Posts: 2
Reputation: 304

### » Tue Jul 17, 2012 11:00 am

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

event:
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:
event:
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
B
45
S
15
G
6
Posts: 795
Reputation: 11,925

### » Tue Jul 17, 2012 12:00 pm

you could do a

-> enemy: spawn bullet
-> bullet: set angle toward mouse.X,mouse.Y"
-> bullet: set angle to angle+random(-10,10)
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,336

### » Tue Jul 17, 2012 3:39 pm

yeah like Yann said. Set it first then add random. Do do both at the same time
B
13
S
5
G
2
Posts: 306
Reputation: 3,262

### » Wed Jul 18, 2012 5:09 am

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

Thanks for the help!
B
2
Posts: 2
Reputation: 304