godot KinematicBody2D move to mousesteemCreated with Sketch.

in godot •  7 years ago 

It is from godot 3 2d isometric demo

extends KinematicBody2D
# Member variables
const MOTION_SPEED = 16000 # Pixels/second
var to = Vector2()
var step = 10

func _physics_process(delta):
    #move_and_slide(motion * MOTION_SPEED)
    move(delta)

func _input(e):
    if (e is InputEventMouseButton
    and e.button_index == BUTTON_LEFT and not e.pressed):
        var gmpos = get_global_mouse_position()
        to = gmpos
        print(' to:' ,to)
        return
    
func move(delta):
    var nto = (to - position)
    if nto.length() < step : 
        return
    move_and_slide(nto.normalized() * MOTION_SPEED * delta)
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!