
So the way I am settling on for now (although I'll probably switch to my navigation mesh idea) isn't as mathy as I'd have hoped, but it does the trick (generally). This way is much faster assuming you are as bad at math as I am, but I am still trying to figure out the mathy way because reasons Your object would then travel to a point on the navigation mesh plane, not according to a projected screen point. The hacky way is setting up a navigation mesh plane veritcally so that it fills the screen. Of course the idea is to get it to work without using if else statements.
#Mouse coordinates how to
I have looked a bit into some math but I am not mathy, so I don't know how to apply any of it yet. The reason this happens, remember, is the projected click always comes back as some value between 0 and 1, so you need to multiply it by some scalar.Īnyway this is as far as I've gotten now, so I too haven't figured it out yet. This got the object to move immediately (teleporting) to the position if I multiplied the projected click position by a large enough floating value, which to me seemed a bit arbitrary, and the value I chose that kept the object within the screen bounds was about 300. When I was playing around, instead of using KinematicBody.move() I tried KinematicBody.move_to(), which is a teleportation function rather than a velocity type function. The projected position is now no longer relative to the origin on which the camera is centered, but now relative to a moving body, and so the velocity will increase even more dramatically. Then I thought I might transform (using Transform.xform(vector)) the projected position by the actors origin. click below the actor he goes down), but this is not the case when projecting the click event position. Intuitively, you'd want the velocity to change depending on where you click relative to the physics body (e.g. This means that the velocity of the physics body changes depending on where you click on the screen, and not where you click according to the physics body. If you use these values to set the velocity of the object you want to move, they are relative to the origin. There are two versions: one that operates in global coordinates (relative to the desktop) and one that operates in window coordinates (relative to a specific window).I'm trying to do the same thing right now.Ĭamera.project_position(click_event_position)


The setPosition and getPosition functions can be used to change or retrieve the current position of the mouse pointer.
#Mouse coordinates update
Compared to the MouseMoved, MouseButtonPressed and MouseButtonReleased events, sf::Mouse can retrieve the state of the cursor and the buttons at any time (you don't need to store and update a boolean on your side in order to know if a button is pressed or released), and you always get the real state of the mouse, even if it is moved, pressed or released when your window is out of focus and no event is triggered. This class allows users to query the mouse state at any time and directly, without having to deal with a window and its events. It only contains static functions (a single mouse is assumed), so it's not meant to be instantiated. Sf::Mouse provides an interface to the state of the mouse. Give access to the real-time state of the mouse.
