[SOLVED] How do I get the angle of the Mouse's movement

0 favourites
  • 7 posts
From the Asset Store
Run and Jump in 3 Dimensions! Take your platformer to the next level!
  • Hey y'all,

    I recently needed the angle of the mouse's movement in one of my projects.

    Essentially, I need the angle in which the user moves the mouse, e.g. for a duration of 0.2 seconds.

    My idea to solve this:

    I came up with the idea to create global variables which store the Mouse.X and Mouse.Y and get refreshed every 0.2 seconds (let's call them "LastKnownX" and "LastKnownY").

    As soon as either of those variables doesn't correspond with the current Mouse's position, the angle of movement is calculated via

    angle(LastKnownX,LastKnownY,Mouse.X,Mouse.Y)[/code:1u2ycl63]
    
    This works okay, isn't very smooth though.
    
    My question now is:
    [b]Is there a better (more effective) way of doing this?[/b]
    
    Thanks for any help.
    _____________________________
    .capx of my setup: https://www.dropbox.com/s/8gkhpl7smf2eh36/MouseAngle.capx?dl=1
    image of my current setup: http://i.imgur.com/3wtATXJ.png
  • What can be more efficient than calculating the angle of point A to point B? Seems like a fine method to me...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well that's why I asked.

    Because I'm still learning and the angle doesn't seem to be very smooth when the mouse is moving smoothly.

    If that's the best solution possible, then I'm fine with that. :)

    Well, maybe there is a better solution for the stuff before the angle() stuff...

  • Ya seems pretty good, not entirely sure what you mean by smooth though. I made a capx where you click in two spots and it shows the angle from the first click, seems fine! If you're working out the new co-ords after 0.2 secs timer it should work in a similar way. https://dl.dropboxusercontent.com/u/495 ... seang.capx

  • I don't know what kind of gameplay you're going for, however, I found out that a simple rotate towards angle instead of set angle makes it look a little smoother.

    Good luck with your project

  • Thanks so much everyone for your responses!

    I took a look at 99Instances2Go 's and 's capxs. I figured, I'd just add the "rotate to" action to my project, because that looks like the easiest and shortest version to me (I'm a lazy person). Thanks for your suggestion!

    This is solved, thanks again!

    (I hope I don't disappoint those who created a capx, I opened them and read through it, I just think that it's less work to just optimize my existing project. Thank you anyways for taking the time to deal with my problem. :) I wish there was a thanks button on this forum...)

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