Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | HarryCourt | |
Old Version | Published before Godot 3 was released. |
I have a small problem. I have two objects in my scene, which I can move with the mouse, drag and place them wherever I want. However, I can not figure out how to be able to pick up one object, and not pick up the other whilst still holding to the other one.
Here is the problem I am facing: Screen capture - 81b58c370c25c3abf23394e38a082fad - Gyazo
Item.gd:
extends KinematicBody2D
# Variables that make it work
onready var spawner = get_node("/root/Scene/Player/Spawner")
onready var player = get_node("/root/Scene/Player")
onready var mouseRotation = 0
# True or False Variables
onready var canDrag = false
onready var isDragging = false
# Sound Nodes
onready var itemDelete = get_node("/root/Scene/Player/Sounds/ItemDelete")
onready var itemRotate = get_node("Sounds/Rotate")
# Stats
onready var GRAVITY = 200.0
var velocity = Vector2()
func _process(delta):
# In order to move the object, you have to click it.
var devMode = checkBoxNode.devCheckBox
if (Input.is_action_pressed("ui_grabItem") && canDrag == true && devMode == true):
dragItem()
# Once let go, it will lock.
if (Input.is_action_just_released("ui_grabItem")):
canDrag = false
isDragging = false
# This has the ability to rotate items
func _input(event):
if event is InputEventMouseButton:
var devMode = checkBoxNode.devCheckBox
if event.button_index == BUTTON_WHEEL_UP && isDragging == true && devMode == true:
rotateRight()
if event.button_index == BUTTON_WHEEL_DOWN && isDragging == true && devMode == true:
rotateLeft()
# These are basic functions that have no need for changing.
func rotateRight():
mouseRotation += 5
itemRotate.play()
self.set_rotation_degrees(mouseRotation)
func rotateLeft():
mouseRotation -= 5
itemRotate.play()
self.set_rotation_degrees(mouseRotation)
func dragItem():
isDragging = true
var mousePos = get_global_mouse_position()
self.set_position(mousePos)
if (Input.is_action_just_pressed("ui_deleteOnItem")):
itemDelete.play()
# If the mouse is hovering over the object, it can pick it up.
func _on_Item_mouse_entered():
canDrag = true
func _on_Item_mouse_exited():
canDrag = false
var devMode = checkBoxNode.devCheckBox
if (Input.is_action_pressed("ui_grabItem") && devMode == true):
canDrag = true
if (Input.is_action_pressed("ui_grabItem") && devMode == false):
canDrag = false