How do I write this Expression.....

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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!!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here you go.

    [attachment=1:bibxagvw][/attachment:bibxagvw]

    [attachment=0:bibxagvw][/attachment:bibxagvw]

  • Hi, you shoud put a condicional event

    here the fix

    https://www.dropbox.com/s/o083tf9oxkkds ... _r173.capx

  • 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.

  • 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)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)