How do I write this Expression.....

Get help using Construct 2

Post » Tue Jul 01, 2014 2:09 pm

Most of the expressions I have completed so far have been trial and error or lucky guesses based on my limited knowledge. I can't seem to figure this one out though. I have attached a CAPx of this problem to the post.

I have an object (Hero) that is pinned to another object (Anchor). Currently Hero unpins and moves to the right of the anchor 50 pixels whenever you click/touch the screen. Super simple.
Is in Touch > Hero> Set position (Anchor.X +50 , Anchor.Y + 0)

I only want the hero to move 50 pixels in X. But I'd like it to move in a negative or positive 50 pixels based on where the mouse clicks. Mouse clicks anywhere to the left of the anchor, Hero goes left 50 pixels. Click anywhere to the right, Hero moves right 50 pixels. Obviously, my current setup only allows a +50 in X, regardless of mouse position. I have tried a lot of different setups, but have failed miserably.

Can any of you more experienced people help me figure this out? I'm sure it's really easy, but my expression skills are lacking! Thanks!!
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 28
Reputation: 404

Post » Tue Jul 01, 2014 2:18 pm

Here you go.

forum.capx


Forum (1).capx
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Tue Jul 01, 2014 2:58 pm

Hi, you shoud put a condicional event

here the fix
https://www.dropbox.com/s/o083tf9oxkkds ... _r173.capx
B
48
S
9
G
10
Posts: 200
Reputation: 8,263

Post » Tue Jul 01, 2014 3:05 pm

Ah I see, Thanks! I didn't even think about splitting the formula over 2 lines. I was trying to write the entire expression in one line of commands. I really appreciate it. This will help me solve another issue I have as well.
B
6
Posts: 28
Reputation: 404

Post » Tue Jul 01, 2014 5:37 pm

I haven't looked at the capx, but this is a way to do it in one line using touch, can be easily adjusted for mouse.
Is in Touch > Hero> Set position (Touch.X > Hero.X ? Anchor.X + 50 : Anchor.X - 50, Anchor.Y)
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643


Return to How do I....?

Who is online

Users browsing this forum: beohs, Google [Bot] and 13 guests