Select a specific part of an object to touch?

Get help using Construct 2

Post » Mon Sep 15, 2014 10:21 am

Hey there people. Quick question. I have an image that the player can touch. I want it to react differently depending on where the object is touched.

Example: If the player touches the left of the object it moves right. If it touches the right of the object it moves left. The object in this case being a ball.

Is this possible without pinning 2 other game objects to the original one?
B
5
S
1
Posts: 7
Reputation: 1,261

Post » Mon Sep 15, 2014 10:25 am

Assuming your origin is in the middle of the object, adding a condition would work..

on object touched
system compare two values: touch.x < object.x
- object move left
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 » Mon Sep 15, 2014 10:33 am

Ah yes that worked thank you very much.
B
5
S
1
Posts: 7
Reputation: 1,261

Post » Mon Sep 15, 2014 10:34 am

This could maybe work better:

On object touch/collision/overlapping:
System -> Compare two values (touch.x < object.x + (object.Width / 2))
Or
System -> Compare two values (touch.x > object.x - (object.Width / 2))
---Object -> Simulate control -> Left

Difference being, LittleStain's code would work if you clicked to the left of the object, not actually clicking the left side of the object if the .x wasn't measured from the middle, for example, if you had shifted the default image point. @LittleStain please correct me if I'm wrong but I thought X and Y were measured from the left edge of the object.
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008

Post » Mon Sep 15, 2014 10:42 am

Yeah I took his code and done something similar to what you described. I just said if it is x-10 do one thing x+10 do the other and I have something else for if you click in the middle, this seems to work pretty well.

Thanks for your helps peoples.
B
5
S
1
Posts: 7
Reputation: 1,261

Post » Mon Sep 15, 2014 10:45 am

Ah cool, no worries; happy to help. Good luck with the rest of your developing, :).
Founder of Jadelight Studio, Developer of Libertas Aedifex, regular C2 Help contributor and fan of ambient music and Star Wars.
B
12
S
4
Posts: 255
Reputation: 2,008


Return to How do I....?

Who is online

Users browsing this forum: batto and 21 guests