I am working on a drag and drop turn based game using the mouse and am trying to figure out how to get the movement working, the idea is that each unit has a movement in pixels (say 200 for this example). I have set an anchor at the units starting location and I want it to be able to pick the unit up with the mouse and move it up to the movement value away from the anchor.
the setup here is just using a kinematicbody2d with a child sprite and collisionshape2d.
I have managed to get a crude version working with an if statement that stops the model being moved if the mouse moves more than the speed away from the anchor, but what I want is for the unit to travel up to the maximum distance from the anchor point and then orbit around the anchor at that distance following the mouse.
any ideas on how to achieve that?
this is my code so far:
export (int) var speed = 200
var velocity = Vector2()
anchor = position
screensize = get_viewport_rect().size
mouse = (get_global_mouse_position())
model = position
if mouse.distance_to(model) < size:
selected = true
selected = false
distance = mouse.distance_to(anchor)
difference = anchor - mouse
if selected == true:
if (distance < speed):
#position = get_viewport().get_mouse_position()
position = Vector2((anchor.x - difference.x), (anchor.y - difference.y))