How do I use mouse coordinates with a mirrored sprite?

Get help using Construct 2

Post » Sun Apr 26, 2015 11:51 am

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:
Image

Left way:
Image

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!
Last edited by OGWoodman on Sun Apr 26, 2015 2:08 pm, edited 1 time in total.
B
7
S
1
G
1
Posts: 4
Reputation: 422

Post » Sun Apr 26, 2015 2:05 pm

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.
Last edited by OGWoodman on Sun Apr 26, 2015 2:07 pm, edited 3 times in total.
B
7
S
1
G
1
Posts: 4
Reputation: 422

Post » Sun Apr 26, 2015 2:06 pm

Try posting the URL without the "https://www" part.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Sun Apr 26, 2015 2:13 pm

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
B
7
S
1
G
1
Posts: 4
Reputation: 422


Return to How do I....?

Who is online

Users browsing this forum: SturmIV and 5 guests