Get current position and check if close to

Get help using Construct 2

Post » Thu Nov 21, 2013 12:22 pm

Hi all,

I've got a quick one here.

A while ago i made a system where it checks if a objects position is close to a global variable. Now i want to write all in one line.

What i want:
1. On drop
2. Check if x and y position is close to Global Variable 1(x) and Global Variable 2(y)
3. If yes do actions.

What i did previously to check if is it close to my global variables is:
[Compare two variables] : abs(Objectname.X-p1X) Less than 22
[Compare two variables] : abs(Objectname.Y-p1Y) Less than 22

p1X and p1Y are global variables where i will move it to when you dragged it close enough. These are global variables i put in before so thats alright.

In short.

I want: On drop (drag and drop function) that Objectname.X AND Objectname.Y is within 22 pixels of p1x and p1y ( global variables ) it does my actions. If not there is nothing to do.

All that in one line if possible?

I hope i made myself clear.

Thanks in advance!Allardje2013-11-21 12:24:44
B
10
S
4
G
3
Posts: 169
Reputation: 2,519

Post » Thu Nov 21, 2013 12:41 pm

What's wrong with the way you do it now?

You want to check for two different things, but do it in 1 line?

You could change the compare two values to

if distance(objectname.x,objectname.y,p1x,p1y) < 22

but that would make a circle of 22 pixels around your variables instead of the square you use now.
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

Post » Thu Nov 21, 2013 12:59 pm

Hi Litte Stain :),
Thanks! Well its for about 50+ objects so the less work the better :).

What you say: if distance(objectname.x,objectname.y,p1x,p1y) < 22 is what i need but i can not find the action for this :( I don't know how to get that command into Construct 2

B
10
S
4
G
3
Posts: 169
Reputation: 2,519

Post » Thu Nov 21, 2013 1:09 pm

If it's for 50+ objects you should probably look into doing it with the function object and/or families. Also if many of those objects are instances of the same object you should look into picking instances.

the distance(x1,y1,x2,y2) is just a value you can put into your system compare values event.
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

Post » Thu Nov 21, 2013 1:18 pm

Hey thanks man! It works great !

Yes i am still learning alot and sometimes i find ways, than i try to fine-tune it so it costs less work and less actions.

For all the objects the same check counts but the only difference are the x1,y1 / x2,y2 etc. So every object does the same but the pinned positions are different.

Any way i could make it less work and better handling?

Thanks for the solution! :)
B
10
S
4
G
3
Posts: 169
Reputation: 2,519

Post » Thu Nov 21, 2013 1:27 pm

Is it possible to make the p1x and p1y variables of the objects or is there any other way to create a reference between the objects and their desired pin-position? if so you could just make a function.

on object dropped call function"CheckDistance" with parameters (object.x,object.y,object.pinlocationx,object.pinlocationy)

on function "CheckDistance"
(subevent) - Sytem compare values : distance(param(1),param(2),param(3),(param(4)) < 22

and add your actions.
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


Return to How do I....?

Who is online

Users browsing this forum: Lordshiva1948 and 7 guests