How do I rotate mouse movement around object for weapn wheel

Just started using Construct 2? Post your questions here

Post » Thu Jul 28, 2016 10:37 am

Hello everyone! I'm trying to create a weapon wheel similar to GTA V. That game slows down, the mouse cursor disappears but seems to be locked in the center of the screen and it extends radially. I hope that make sense. You can then "push" it around the wheel to select different weapons. I think most modern radial wheel/weapon wheels in game function like this nowadays.

https://youtu.be/pDGGJIvCTZM?t=39
Image

So I've got a simple and very crude looking weapon wheel system implemented. You hold shift to bring up the weapon wheel. The ammo type switches based on what "ammo/color" I click. Basically, I'd like to create the behavior of the mouse acting like it's locked in the center of screen (or weapon wheel sprite) and can move around highlighting the weapons on the weapon wheel while the player pushes the "locked" invisible mouse. Am I using the correct term? Do I need to clamp the mouse wheel somehow? I found this post but I couldn't get it to work .Hope I explained what I'm trying to do clearly. Thanks for reading my question!

edit: changed the name of my post title to be a more specific question. It was previous "How do I create a GTA style weapon wheel/clamp mouse movemnt"

window-bound-mouse_t63058
Last edited by heyguy on Thu Jul 28, 2016 9:26 pm, edited 2 times in total.
B
28
S
14
G
21
Posts: 179
Reputation: 13,548

Post » Thu Jul 28, 2016 8:55 pm

Here's something similar to what I'm trying to replicate. Instead of the missile circling the ship non-stop though, I need a "free" mouse that is temporarily restricted to this sort of circle movement so that the player can circle around the weapon wheel and quickly select a weapon. I'm gonna spend some time looking at that capx and experimenting but any guidance would be appreciated! Thanks!

how-do-i-make-earth-rotate-around-the-sun_t63895

edit: the way i imagine the weapon wheel working is when the player holds tab or shift, time pauses/slows down the the wheel pops up. The crosshair would disappear, the mouse would essentially "teleport" over to the weapon wheel, lock itself into a circular movement so that mouse movement highlights the weapons on the wheel and the player can select them. On shift/tab release/weapon select, the new weapon is selected and your cross hair should be where it last was on the game layout. Highlighting, changing the visibility of the cross hair and actually selecting the weapons are the easy parts.

Just typing out how I want the system to work makes me realize its not as simple as just locking the mouse movement. If that even is simple :D The "teleportation" of the mouse seems tricky unless I'm over thinking it. I guess I would have to store the location of the cross hair/mouse as I bring up the weapon wheel and place the mouse back there when the weapon wheel is closed.
B
28
S
14
G
21
Posts: 179
Reputation: 13,548

Post » Thu Jul 28, 2016 11:26 pm

I think you are making it to difficult.

First. You can not set the mouse to a position, other then the position the player moved the mouse physical to.
And you should not be able to do that in a 'browser game'.

That said (and accepted), you can not use the mouse to acces things in the wheel.
And now it all got a lot more simple. Just as example:

https://www.dropbox.com/s/fdnydudwf81q3 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jul 29, 2016 1:10 am

You could turn the cursor invisible during selection and turn a different cursor visible. Put its origin way below the actual image, so the cursor appears over the weapon options and its origin is at the center of the wheel. Then use the "set angle to position" action:

key SHIFT is down -> cursor set angle to (mouse.x, mouse.y)

I'm not sure what to do to get the original cursor back to the right position, though.
Eh, Steve!
B
114
S
54
G
13
Posts: 112
Reputation: 16,120

Post » Fri Jul 29, 2016 10:26 am

@99Instances2Go Thanks for the help and info! This is definitely a good way to get around the problem of re positioning the mouse after selecting a weapon. I'm wondering if maybe I'll keep this in mind but I still really have my heart set on something GTA V-like.

@calebbennetts Awesome! Thanks! I think this is what I'm looking for! It's not working the way it looks like it should though. The cursor seems almost locked into place on its side. The cursor is placed upright in the editor before hand though. I used absoluteX and absoluteY and that actually rotates around the circle but it works wonky. I added short gifs of both. Other cursor there for testing.

Image
mouse.x,mouse.y
Image
mouse.absolutex,mouse.absolutey

Anyway, I'd appreciate some more help if you can calebbennetts. I think I've also come up with a way to replicate this behavior now. So the whole screen will have these invisible zones that correspond with specific weapons. The mouse is always hovering over a weapon unless the mouse is in the center. Player won't necessarily move the mouse around like a wheel but that's ok. It might work better that way. I think this can get very close to the effect I'm looking for. I can check whether the mouse is in the "zone" of any particular weapon and have the weapon highlighted or flashing. What does everyone think of this method? Seems like a pretty good workaround for an artist like me. I'd really like to get what calebbennetts suggested working though. That way seems like it's all ready to go once I can get the angle of the cursor to point to the mouse correctly. Here's a pic of what I'm thinking of.

Image
B
28
S
14
G
21
Posts: 179
Reputation: 13,548

Post » Sun Jul 31, 2016 5:27 pm

Message: Siluser can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I'm thinking you should just make an invisible, long and thin sprite, make the origin something like "0, 3", have it set angle towards mouse.X and mouse.Y, and use overlap events for the different colors.


Take this for example:

https://googledrive.com/host/0B3W5p8PE6c_7TEt3MWZxQnBQY0k

I put it together quite hastily, but the point should get across.
B
3
Posts: 4
Reputation: 183

Post » Sun Jul 31, 2016 6:21 pm

@Siluser: Your idea would work similarly to mine, but I think it would also encounter the same problem.

I think the problem is that the weapon wheel is probably on its own layer with a (0,0) parallax, right? So unless you're in the very top-left of the map, the mouse is actually really far away from the wheel's center, and any movement only means a tiny change in angle.

Meanwhile, looking at absolute x and y, it seems like that refers to the mouse position for the entire screen, not just your game's window. Possibly not a problem once you port to mobile?

So a potential workaround: you could use (mouse.x, mouse.y), set the weapon wheel's layer to a (100,100) parallax, then set the wheel's position to (scrollx,scrolly) every tick. It does make the rotation work correctly. However, you would have to put your onscreen buttons in a separate layer or move them every tick as well. This method also makes the weapon wheel look a bit jumpy when it repositions, but it'll only be visible when the timescale is very low, so it might not be noticeable.
Eh, Steve!
B
114
S
54
G
13
Posts: 112
Reputation: 16,120

Post » Wed Aug 03, 2016 6:28 am

calebbennetts wrote:@Siluser: Your idea would work similarly to mine, but I think it would also encounter the same problem.

I think the problem is that the weapon wheel is probably on its own layer with a (0,0) parallax, right? So unless you're in the very top-left of the map, the mouse is actually really far away from the wheel's center, and any movement only means a tiny change in angle.

Meanwhile, looking at absolute x and y, it seems like that refers to the mouse position for the entire screen, not just your game's window. Possibly not a problem once you port to mobile?

So a potential workaround: you could use (mouse.x, mouse.y), set the weapon wheel's layer to a (100,100) parallax, then set the wheel's position to (scrollx,scrolly) every tick. It does make the rotation work correctly. However, you would have to put your onscreen buttons in a separate layer or move them every tick as well. This method also makes the weapon wheel look a bit jumpy when it repositions, but it'll only be visible when the timescale is very low, so it might not be noticeable.


If you want to track the mouse from a layer that has parallax, that's what LayerToCanvas and CanvasToLayer is for :)

You can move/relate things on different layers with different parallax values using these expressions ;)

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Sat Aug 06, 2016 7:37 am

Hey all! Thank you for all the help! Been working on other parts of the game but I'm back at this specifically. I'm not sure what I'm doing wrong but I just can't get the cursor to point to the correct mouse position, no matter what I try.

@calebbennetts I tried you workaround but it still won't read the mouse position correctly. Even if it did, the jitter-ing is difficult to ignore and I think I've implemented the LayerToCanvas and CanvasToLayer expressions correctly into my events. If I can't get it to work that way though, I can pause the game while selecting a weapon. No more jitter-ing.

@SoldjahBoy Thanks for your help. I took a look at the example and I think I got it to work in my project. Still, though, the cursor doesn't correctly point at the mouse. Before LayerToCanvas and CanvasToLayer, the cursor wouldn't rotate fully. Now it does but it's not pointing to where the mouse is.

Am I doing something wrong with the sprite? I want to describe the way the cursor is acting like there's actually a 2nd invisible cursor and the 2nd cursor is the one actually pointed towards the mouse.

I recreated the problem in a small capx. I made a small, thin sprite like @Siluser and I have 3 different ways of controlling the cursor on that capx. None of them have the cursor pointing at the mouse correctly. Can anyone take a look at the file and troubleshoot it please? Shift brings up the "weapon wheel". Also including the pic of the events on my level. Am I using the LayerToCanvas and CanvasToLayer expression correctly? Is the mouse even on a "Layer"?

edit: Presumably the mouse is on the "Game" Layer with the player collision, enemy collisions and other things like that right? The layout size of this capx is the same size of my prototype level, 2048x1024. Adding a gif of LayerToCanvas/CanvasToLayer working in my level. It works fully rotates unlike mouse.x,mouse.y and the wheel/cursor/icons are on the "UI" layer but I can't get the cursor to spin correctly regardless.

https://www.dropbox.com/s/s0qo4kl1s8e1k ... .capx?dl=0
Image
Image
B
28
S
14
G
21
Posts: 179
Reputation: 13,548

Post » Sat Aug 06, 2016 10:08 pm

here fixed for you

https://www.dropbox.com/s/b3dlvchxp1suh ... .capx?dl=0

all you need is
(dont set angle towards
just set angle from centre wheel to mouse postion
note the addition of ("UI") to identify specific layer and make sure no parallax or scale on that layer

eg

set angle to >>>> angle(hud_weaponWheel.X, hud_weaponWheel.Y, Mouse.X("UI"), Mouse.Y("UI"))

look fwd to yr game.....
...
B
44
S
23
G
7
Posts: 288
Reputation: 7,989

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest