# How do I create object in hitbox that isn't square?

Get help using Construct 2

### » Tue Aug 01, 2017 4:56 pm

I have a large diamond shape that doesn't take up the whole screen, it does change size though.
The diamond and image size is 2 parts width and 1 part height.
100 width, 50 height
1000 width , 500 height... etc

What I currently have isn't using a hitbox. It works, but is a mess.

I pick a random width.
I then compare the X position to the width, This gets me a percent.
I compare to 50%.
If it's below 50% of the width I use that number.
50%=50%..
If it's above 50% I use 100-X%.
I then use the % and compare it to the height measurement.
I turn the percent back into a value coinciding with height value and divide it by 2.
I then randomly pick Y from center point Y +/- from the previously found number.

I have a few of these steps combined, I just simplified them here.
It does work welk, but it seems overly complicated.
I think I'm just missing a native expression or am over complicating it..

Is it possible to spawn objects in a hitbox that isn't square?

I suppose I could add hidden objects where I don't want it to spawn, but I usually try to avoid that.
Would using hidden objects be better?
"Create here, but not touching those"
Does this cause the system to have to pick more than once sometimes?
B
59
S
33
G
13
Posts: 223
Reputation: 12,105

### » Tue Aug 01, 2017 8:05 pm

Hello,

If you dont want to post a .capx you send me a PM with it.

Im not really sure about what you want but i thinks i can help. (Im french you can try to explain just what you want)

Best Regard,
Casimir
B
10
S
2
Posts: 35
Reputation: 680

### » Tue Aug 01, 2017 10:13 pm

Break up the shape in triangles, using imagepoints.

First choose a random triangle.
Then choose a random point like this.

https://www.dropbox.com/s/at7rdg1w357mu ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

### » Wed Aug 02, 2017 5:11 am

It seems exactly what I need, but It is confusing a small bit to me. I will have to dissect it.
I understand how to use it as it is, but would like to know a small bit more.

Why are you setting r1 and r2 to random(1) instead of just setting it to 1?
How is it picking a random point? The only random I see is random(1).
I never used or seen a random without two limits. Random(0, 10) etc.

Can you give a simple explanation for the rX and rY formula?
I do notice that one controls the X and one controls the Y.
B
59
S
33
G
13
Posts: 223
Reputation: 12,105

### » Wed Aug 02, 2017 8:26 am

random(1) generates a number between 0 and 0.9999999999999999999
random(5) generates a number between 0 and 4.9999999999999999999

It needs 2 randoms, else the distribution will be more dense around the centre. (barycentre)

Explanation:
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

### » Wed Aug 02, 2017 12:43 pm

B
59
S
33
G
13
Posts: 223
Reputation: 12,105