How do I use mouse coordinates with a mirrored sprite?

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I really do apologize if this has been asked, but I went through many threads including the FAQ and couldn't find something similar. It's probably because I've been trying to make this work for a while/tired but I just can't wrap my head around this.

    What I want to do exactly is when I rotate a sprite (in this case, arms that are holding a gun) as a separate object from the player (pinned to player) I want the gun barrel to line up with my mouse. (If you've ever played Starbound, that's the only game I can think of for an example, where the arms move independently of the body when something is equipped in your hands) On the right side of the character, this works fine. When I move my mouse to the left side however, the gun doesn't mirror it just keeps turning, ending up in an upside down gun pointing the opposite direction.

    I've tried pointing it towards -mouse.X/-mouse.Y but apparently that's far below the screen. I've badly drawn up the examples of what I'm picturing in my head to better illustrate it: (the red dot is where the mouse pointer was)

    Right way:

    Left way:

    And here is the capx : dropbox.com/s/j6xmnw3ia1n0mqt/test1.capx?dl=0 I'm sure it's probably simple and I'm just over thinking it wayyyyyyyy too much.

    Any help would be much appreciated!

  • Okay, so I've half solved the problem, by removing the 'mirror' and 'set angle' actions and adding the 'flip' action I can now aim both ways, but I have another problem now. If I aim very slowly it will correctly switch between the sides each time, but if you move the mouse too fast to either side it won't flip back. Hmm.

    Too bad I can't post URLs. Lol.

    I'd try to get around it but that's probably against the rules.

    updated capx? dropbox.com/s/kupox2o149omc67/test2.capx?dl=0

    Eyy, it worked. Thank you ramones.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try posting the URL without the "https://www" part.

  • Well, I've answered my own question. I will update this post with my answer. (I hate it when people say they've fixed something and don't post how lol.)

    Okay, so I'm not sure if this is the "right" way of doing it, but it works for me 100%.

    As an 'every tick' event I added the arms/gun (herein referred to as gun) to be NOT flipped.

    I also added the set angle of gun to mouse.X and mouse.Y position here in the every tick event.

    In the gun event for checking if it was between 89 and 269 degrees I set the gun to FLIPPED.

    Thanks a heap, now it's time for some sleep.

    In my infinite wisdom I have forgotten the final capx.

    dropbox.com/s/jldjd8mjq3ryqx0/finaltest.capx?dl=0

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