How to determine direction based on mouse position? 8 directions.

Ok, so in my game I have the player actor follow the mouse position, and I need to determine which direction the actor is traveling so I can play the right animation and also know where to fire bullets from. It's not top down, so I can't just rotate the actor. I would like to have 8 directions for images/animations, but the firing should be more fluid. I have tried a number of things already, like using vectortoangle, and working out between which to values would be left, right, up, etc but it's not working properly.
Any help would be appreciated
Thanks :)

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    round( self.Rotation /45) will give you 8 values.

  • MattcusMattcus Member Posts: 85
    edited July 2015

    I'm not rotating the actor though, so I can't use that to determine direction, is there another way to do it?
    I was hoping there was a way to work out which direction the actor was travelling.

    Maybe having another actor on top of the player which does rotate, could be a solution?

  • ArmellineArmelline Member, PRO Posts: 5,369
    edited July 2015

    Can definitely be optimised, I got very little sleep last night :D I'll be shocked if there's not an easier way to get the direction information using a similar method. All directions are given equal weight (45 degrees).

    This is a vector-to-angle method, but without seeing the animation or what "not working properly" means exactly it'll be hard to really improve upon what you've already done.

    See the text display for a fun little tip.

  • MattcusMattcus Member Posts: 85
    edited July 2015

    Thank you so much, this is exactly what I needed. It's very similar to what I had done, however for some reason mine wouldn't register left, and up left and down left would only work if going around anti clockwise. But it works fine now, thanks again!

Sign In or Register to comment.