According to all found resources (and basic math), to find out what direction one must go to get to a target point, you subtract your position from the targets position. I am using this in a simple dash for my game. However, the problem is that, no matter if I base it off of screen or world coordinates, it always gives me two problems: first, no matter where I position the cursor relative to the player or the center of the screen (they are the same place), the X value of the direction is almost always negative, pushing my character to the left. Similarly, the Y value is often negative, despite the cursor being above the player.
Here is the code I am using (also, if it makes any difference, I am using the rendercam camera):
local dash_speed = 1200 local dash(self, mouse_x, mouse_y) -- i also prevent holding down the mouse self.velocity = vmath.normalize( vmath.vector3( mouse_x, mouse_y, 0 ) - go.get_world_position() ) * dash_speed end function on_input(self, action_id, action) -- some other inputs if action_id == input_dash then -- pre-hashed dash(self, action.x, action.y) -- i also have some code so you can't just hold the dash button end end
I have tried swapping out
Sorry if I am missing anything obvious (which is most likely the case), I am both new to Defold (although it is quite easy to learn) and bad with vectors. Thanks for any help!