# How do I spawn an obj on the top edge of an angled object

Get help using Construct 2

### » Mon Oct 05, 2015 9:33 pm

I am trying to spawn bullet objects randomly along the top edge of a rectangular player controlled object.

The problem is that the player controlled object can rotate a bit in each direction and is therefore at times angled. I have randomized the X coordinate to spawn the bullet at (along the player object top edge), but I am not sure what to do for the Y - it may have to deal with the slope of the angle? but I am not sure.

I have tried to use Image points to spawn the bullets but I would rather not so that I can spawn objects at any random point along the top edge of the player object.

Thanks in advance. I know this has been tough for me to figure out so kudos to whoever gives it a go.
B
90
S
31
G
11
Posts: 101
Reputation: 11,337

### » Mon Oct 05, 2015 10:10 pm

I guess you could put an image point on each of the top corners and spawn at:

x = lerp(player.imagepointx(1),player.imagepointx(2),random(1))
y = lerp(player.imagepointy(1),player.imagepointy(2),random(1))

offcourse you should choose the random number between 0 and 1 before using it inside the expression,
that way the position will be on the line between the points..
Last edited by LittleStain on Mon Oct 05, 2015 10:15 pm, edited 1 time in total.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Mon Oct 05, 2015 10:11 pm

You could also do it like this with the "move at angle" action.

create bullet at (player.x, player.y)
bullet: move player.height/2 pixels at player.angle-90
bullet: move random(-0.5,0.5)*player.width at player.angle
B
98
S
36
G
132
Posts: 5,525
Reputation: 84,013

### » Mon Oct 05, 2015 10:16 pm

R0J0hound wrote:You could also do it like this with the "move at angle" action.

create bullet at (player.x, player.y)
bullet: move player.height/2 pixels at player.angle-90
bullet: move random(-0.5,0.5)*player.width at player.angle

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Mon Oct 05, 2015 10:30 pm

Both workable solutions. Thanks guys.

I was embarrassed to even say what I had.. I was spawning bullets at random(1,15) image points, and then adjusting each bullets X by +/- 30.

Anyways, now it's perfect. Thanks again you two.
B
90
S
31
G
11
Posts: 101
Reputation: 11,337