Help with math and absolute-relative mouse coord

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I need mouse to be always in maximum 300px range (radius) from object. If distance between mouse and object is greater than 300px then it must be in 300px range, if distance is smaller then do nothing.


  • I solved this by first checking the distance between wherever and mousex/mousey using distance(whateverx, whatevery, mousex, mousey). If it's under 300, set position to mousex/mousey, if it's over 300, set position to the center of the circle and use 'move at angle' 300 pixels towards the mouse using angle(whateverx, whatevery, mousex, mousey)

  • Does "move at angle" use timedelta?

  • No, using move at angle>100 pixels at angle 0 is the same as doing set x to .x+100, so you'd need to move 100*timedelta pixels.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It will then be towards mouse in range of 300. That's not what i need.

    For ex. i'm moving mouse to the right side of the screen (any resolution, for ex. 1280) - the object will move towards it but only 300px. Then i move mouse to left on 200px - the object still 300px towards mouse pos.

    What i need is when i move mouse from right side to left on 200px, the object should do the same - move at 200px. That's why i need to "jail" (?!) mouse in the range, not set object towards it.

  • I'm afraid I don't quite understand what you're trying to achieve. Are the "set mouse x/y" actions in mouse/keyboard object what you're looking for?

  • I'm trying to implement Madness Interactive control scheme

    + System: distance(Body.X, Body.Y, MouseX, MouseY) Greater than 100

    -> MouseKeyboard: Set mouse X to Window.ClientX + Body.X + ( 100 * sin( angle( Body.X, Body.Y, MouseX, MouseY ) ) )

    -> MouseKeyboard: Set mouse Y to Window.ClientY + Body.X + ( 100 * cos( angle( Body.X, Body.Y, MouseX, MouseY ) ) )

    and that not working correctly

    Also why i need this scheme is that i have direct control of hand with weapon and no crosshair at all


    Arima sorry i tried your solution without proper understanding, solved but partially - movement seems too jaggy.

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