Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | joshua7v |
What I want to achieve is: while holding down the mouse, create an instance of an object and display it on screen, move mouse(while holding down left button) will move that object, release button will drop the object(rigidbody with gravity). Current situation: basically works, but the object will go back to the click position after releasing mouse button. I have no idea why.
func _physics_process(delta):
var scene = preload("res://a-scene.tscn")
if Input.is_action_just_pressed("click"): # mouse down
node = scene.instance() # node is a rigid body
node.can_sleep = false
add_child(node)
if Input.is_action_pressed("click"):: # mouse holding down
node.position.x = get_local_mouse_position().x
if Input.is_action_just_released("click"): # mouse up
print('release')
A suggestion for improving your code (once you figure out your problem ). Place this code, var scene = preload("res://a-scene.tscn")
, outside of the _physics_process()
(near the top of the script). This may help with performance.
Ertain | 2021-02-16 22:20