0 votes

Hi,

I am working on a drag and drop style game and am trying to get the movement working correctly, I want to have the model only move up to its speed away from its starting point each turn and I can use clamp to do this, if I set clamp to the x and y it works by locking it to a square. but I want it to be locked to a circle.

any ideas on how to achieve that?

this is my code so far:

extends KinematicBody2D

export (int) var speed = 200

var mouse
var model
var selected
var anchor
var distance
var velocity = Vector2()
var screensize
var destination
var vector
var difference

func _ready():
    anchor = position
    screensize = get_viewport_rect().size

func _physics_process(delta):
    mouse = (get_global_mouse_position())
    select_model()

func select_model():
    model = position
    if mouse.distance_to(model) < size:
        if Input.is_action_just_pressed("mouse_left"):
            selected = true
    if Input.is_action_just_released("mouse_left"):
        selected = false
    get_input()

func get_input():
    distance = mouse.distance_to(anchor)
    difference = anchor - mouse
    if selected == true:
    position = Vector2((anchor.x - difference.x), (anchor.y - difference.y))
    position.x = clamp(position.x, anchor.x - speed, anchor.x + speed)
    position.y = clamp(position.y, anchor.y - speed, anchor.y + speed)
asked Jun 10 in Engine by grimvoodoo (12 points)
edited Jul 26 by grimvoodoo

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.