0 votes

This problem seems to be a lot harder in concept than it should be.
The Goal:
to have it where in the game the player can use their mouse to click, drag, drop tile pieces.

Nodes:
KinematicBody2D > Sprite & CollisionShape2D

Script: 1 on KinematicBody2D
Pastebin Link to script

With all of this I thought I had it:

  • The program is checking my Mouse Position and able to store it as a Vector2
  • Check if LMB & Cursor are in the same place
  • move an object anywhere.

It slightly does. the problem is the LMB has to be on first before touching the object
and when it does move its only in a small incremental burst in the almost random direction slightly influenced by the mouse movement.

I have no idea where to go from here. If someone has a better idea, a guide, hint or something pleese I could really use it.

in Engine by (16 points)

Did you set the KinematicBody2D as pickable? Maybe it helps

Yes, I did. I had figured that would be one thing that would show up.
Just in case here is my project folder, it just uses the default icon.
https://drive.google.com/file/d/0B0iEQfbunEIFNVpzVlZEUGkxZUE/view?usp=sharing

So on another post, I was given some help.
Changed:

_process  ::  _fixed_process
set_process :: set_fixed_process
self.set_pos(Mpos) :: self.set_global_pos(Mpos)

(I can also just remove self. from that to as its not nesserary)

Unfortunately, this still didn't help. I took a Gif capture of what the game is doing here:
enter image description here
Want to point out that my Left Mouse Button is held down the whole time to get it to move at all.

2 Answers

0 votes

Well. I know you guys tried but i had better help on the Reddit page on this. but I will give you what I found.

The major problem with my last code that was causing it was the fact that _on_KinematicBody2D_mouse_enter():can't be called multiple times. and I was putting the Left Mouse Button var in where I could have just focused on Mouse being in or out of the frame.

I also added one new check in the code to make sure that even if the mouse escapes the hitbox of the object, as long as I am still holding down the Left Mouse Button it means I am still dragging so keep going.

Anyway. here is the new script

by (16 points)
0 votes

Here is a copy of your pastebin for future references. Maybe the link is broken in the future:

extends KinematicBody2D

var Mouse_In = false
var Mpos = get_global_mouse_pos()
var Objectdrag = false
# Mouse_In acts as a check switch for if the mouse has entered the object's hitbox
# Mpos is a simple var to keep check on mouse position, is updated in process
# Objectdrag is an extra var to keep the mouse from dropping the Object if it is still dragging but escapes the objects hitbox
func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    Mpos = get_global_mouse_pos()
#Updates the Mpos on Current pos
    if Mouse_In == true:
        if Input.is_mouse_button_pressed(BUTTON_LEFT):
            set_global_pos(Mpos)
            Objectdrag = true
        else:
            Objectdrag = false

func _on_KinematicBody2D_mouse_enter():
    Mouse_In = true

func _on_KinematicBody2D_mouse_exit():
    if Objectdrag == false:
        Mouse_In = false

I'm glad you fixed it.

by (680 points)
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.