Hi, I'm making an Isometric (2D) game. In somewhat of a similar style as Ultima Online or the Diablo series, I want to control my movement by the mouse. Point-click-move (for now). I'm a newb to Godot, and to game-making, but I have some small programming experience...
It is sad to say how long I've been working on this issue, so I won't say it haha..., but I can say that I have tried researching, reading documentation, YouTube videos, google, math tutorials, and spoke to some friendly folks on the Discord server who tried to help me. I feel like I'm missing some resources though.
I'm just kind of trying to come up with some sort of working code, and then build off of that eventually.
This is the original code I was writing (which is incomplete), I'm just hoping someone could tell me if I'm in the right path.
func _input(event)
var currentPos = Vector2(self.get_pos())
var destVectorPos = Vector2(event.x, event.y)
#figuring out the distance between two points which i'm sure there is a function somewhere
var xDist = sqrt(destVectorPos.x - currentPos.x)
var yDist = sqrt(destVectorPos.y - currentPos.y)
distance = sqrt(xDist + yDist)
if(event.type == InputEvent.MOUSE_BUTTON and event.pressed):
if(event.button_index == BUTTON_LEFT):
startTime = get_process_delta_time()
#this is where I figure out how to move "distance" over "time"
#lerp?
#also should I be doing this in fixed_process function?
#seems like there should be a much easier way i'm missing
print ("The current position I'm at is: ", myPos)
print ("The mouse clicked here: ", event.x, ",", event.y)
print ("The distance between us is: ", distance)
Anyways, after showing the nice folks on Discord, they provided me this idea....
extends KinematicBody2D
var is_moving = false
var move_to_pos = Vector2()
var event = InputEvent()
var speed = 200 # pixel/second
func _ready():
set_process_input(true)
set_fixed_process(true)
func _fixed_process(delta):
if is_moving:
var direction = move_to_pos - self.get_global_pos()
if abs(direction.length()) < 0:
#we're at the position we want to be
is_moving = false
return # stop here, so we don't move any further
direction = direction.normalized()
self.move(direction * speed * delta)
# if is_colliding():
# # do all your collision stuff here
# pass
func _input(event):
if event.type == InputEvent.MOUSE_BUTTON and event.pressed:
move_to_pos = Vector2(event.x, event.y)
is_moving = true
Where my Kinematic2D body sort of "nudges" a couple pixels North on the Y-axis when clicking anywhere, and then stops.
Any thoughts?
Thank you!