Containing mouse cursor to a circle around the hero

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I am making a game where you move in eight directions and aim and shoot with the mouse.

    What I would like to do is constrain the cursor to a circular, ~150px radius around the player. It is important that the mouse itself be constrained, not just the visual of the crosshair. The mouse cursor and crosshair should be 1:1.
    Within the 150px radius the mouse should act normally. Which is to say, I'm not looking for the cursor to move around the edges of the circle, but to be contained within. The cursor being on the edge of the circle should not inhibit rotating around the player, however.

    I would also like the mouse cursor to inherit the directional speed of the player so that I can use an advanced camera system without the aim becoming misaligned (since the mouse cursor does not scroll at the same speed as the screen).


    I hope this isn't as complicated as I've convinced myself it is :)

  • I don't think you can constrain the mouse pointer. I've made a game that uses the mouse to move and shoot using a system similar to what you describe, I used an active object as a fake mouse pointer that scrolled the screen when over a circular zone surrounding the player.

  • You have to make a crosshair that's an active object and then hide your mouse. You cant control the computers mouse directly.

    Please login to see this link.
    Please login to see this link.|Please login to see this link.|Please login to see this link.

  • Well it doesnt make a difference to me how its achieved. Right now I have a crosshair set to xmouse and ymouse, but how do I make it so that the crosshair never leaves that area?

    I need more than a visual effect where only the crosshair stops at the edge of the circle but the (invisible) mouse keeps going, though. The problem is that once the mouse and the crosshair aren't aligned it feels awful to play.

  • Right now I have a crosshair set to xmouse and ymouse, but how do I make it so that the crosshair never leaves that area?

    Make the circle area an invisible solid object. Use a second active if you just want the perimeter visible.
    Use the code: Always
    + Mouse Pointer is overlapping circle --> Set x crosshair to x mouse, set y crosshair to y mouse

    I need more than a visual effect where only the crosshair stops at the edge of the circle but the (invisible) mouse keeps going, though. The problem is that once the mouse and the crosshair aren't aligned it feels awful to play.

    Make it so that actions only occur when the mouse pointer is overlapping the circle? Without seeing any examples of what you have already and what the problem is it's hard to advise you.

  • See, that wouldn't work because once the mouse cursor leaves that perimeter but the crosshair stays, there's a mismatch. Let's say you're aiming all the way at 90 degrees. You want to quickly turn around to 270 degrees to shoot a bad guy behind you. There would be a delay in all crosshair movement until the mouse cursor returns to the perimeter zone.

    I was avoiding posting an mfa because I had just been experimenting, so this example is really buggy and the code in there is very sloppy but if it helps illustrate what I'm trying to do better. (I hope sendspace is ok)
    Please login to see this link.

    It sort of shows what I'm trying to do, but it doesn't work properly.

  • Could you add another condition, you can use the overlapping one and a NOT Overlapping one.
    The first is like exposed before and the second you can just adjust the direction of the crosshair over the border of the "good area", supposing it is a circle is just a little trigonometry calculations.
    Is this a possible solution?

    Edited once, last by 1Ombra1 (January 13, 2018 at 11:18 AM).

  • Please login to see this attachment.
    Try this, I just tethered the active onto a actionspot, then used another active as the crosshair, did a distance check with the crosshair and then position accordingly to the distance restriction. The distance check forms a perfect circle, then you just place a graphic to show where the radius is. You must be rotating the player active in order for it to work.

    Professional Game Developer

  • Please login to see this attachment.
    Try this, I just tethered the active onto a actionspot, then used another active as the crosshair, did a distance check with the crosshair and then position accordingly to the distance restriction. The distance check forms a perfect circle, then you just place a graphic to show where the radius is. You must be rotating the player active in order for it to work.

    Yeah, this is basically the starting point of what I'm trying to do. But go into your code and put an "always hide mouse cursor" event and play around with it and maybe you'll see what I mean about it feeling bad because of the delay when the actual mouse cursor is outside the boundary but the crosshair remains. THAT's the big obstacle I'm trying to get past.

    Quote


    SolarB
    From an old example I dug up. You can change the distances etc in the crosshair values. I hope this is what you're after?

    Thank you for trying to help, but this is sort of the opposite of what I'm after. I don't mind if the crosshair overlaps the player, it's the outside boundary that's the problem.

    Quote

    Could you add another condition, you can use the overlapping one and a NOT Overlapping one.
    The first is like exposed before and the second you can just adjust the direction of the crosshair over the border of the "good area", supposing it is a circle is just a little trigonometry calculations.
    Is this a possible solution?

    I'm not sure what you're saying here.

  • Here are a couple ideas:

    1) don't hide the mouse cursor
    2) use a second pointer graphic, which is the actual mouse position. the crosshair circle itself is constrained. A lot of games choose to do this and it eliminates your problem. The mouse pointer graphic is the actual +, and the other graphic is the border or vice versa

    I don't really understand why you don't want the actual mouse pointer visible, but it seems really odd to me and I can't think of a way you could "fix" the problem without it being awkward. This might be a case of overcomplication!

    Best person at writing incomprehensible posts. Edits are a regularity.

    Edited once, last by casleziro (January 14, 2018 at 1:16 AM).

  • I've put a minimum boundary just in case. If you want the crosshair to still overlap the player you can set MinDist in the alterable value to 0. I don't think there's a way to hard constrain the mouse itself since the cursor is tied to Windows, you would always have that delay coming back to it.

    Please login to see this link. | Please login to see this link. | Please login to see this link. | Please login to see this link.

  • I don't think there's a way to hard constrain the mouse itself since the cursor is tied to Windows, you would always have that delay coming back to it.

    Firefly's movement object can constrain the mouse, it'd be good if Clickteam added that kind of function to the base engine.

    Professional Game Developer

  • Here's an example I made awhile back. It sets the camera to a midpoint position between the player and the mouse, but it can be restricted to a set distance away from the player. In this case you could replace the camera object for your custom mouse object to restrict the distance away a player can reach from the player.

    There is a mouse object that can set the actual mouse X and Y positions, so restrict them using that object, setting the positions to the position of the camera object if the distance is past your max distance value.

  • how do you mean "clamped"?

    clamped means you limit the value like a combined max and min, so that you take the max between 0 and the relative position, as well as the min between 150 and the relative position.

    The actual mouse cursor will be hidden. The crosshairs will be positioned at the hero's position plus the mouse's distance from the mouse starting position (sometimes called the mouse delta), but limited to that circle.

    if the distance from the character to that offset that positions the crosshairs is going to be greater than 150, you can limit it using trig functions to keep it within that circle. there's a few ways to do this but one i was thinking of involves finding the angle between the crosshairs and the hero (like with the arctan2 function or whatever CTF uses). you can use that found angle, putting it into the cosine and sine functions to constrain it to that circle.


    Sent from my iPhone using Tapatalk

  • clamped means you limit the value like a combined max and min, so that you take the max between 0 and the relative position, as well as the min between 150 and the relative position.

    The actual mouse cursor will be hidden. The crosshairs will be positioned at the hero's position plus the mouse's distance from the mouse starting position (sometimes called the mouse delta), but limited to that circle.

    if the distance from the character to that offset that positions the crosshairs is going to be greater than 150, you can limit it using trig functions to keep it within that circle. there's a few ways to do this but one i was thinking of involves finding the angle between the crosshairs and the hero (like with the arctan2 function or whatever CTF uses). you can use that found angle, putting it into the cosine and sine functions to constrain it to that circle.


    Sent from my iPhone using Tapatalk

    so whats the event look like?

    always -> set Xcrosshair to Xcharacter + range(xmouse,0,150*cos(Xcharacter) ??

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!