#Can I make a sprite3d move by clicking it first then moving it with WASD?

1 messages · Page 1 of 1 (latest)

celest mist
#

this is my code

extends Sprite3D

var clicktomove = false
var speed = 7

var velocity = Vector3.ZERO

func _on_area_3d_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
if event is InputEventMouseButton:
print_debug("clicked")
clicktomove = true
else:
clicktomove = false

func _physics_process(delta: float) -> void:
if clicktomove:
var move_direction = Vector3.ZERO
move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left")
move_direction.y = Input.get_action_strength("up") - Input.get_action_strength("down")

    velocity.x = move_direction.x * speed
    velocity.y = move_direction.y * speed

i want the sprite to only move if i clicked on it first but only the "clicked" print works in this code. its not like click and drag. can i get some help?

lean wave
#

Try putting a print with it, my guess is that when you move the mouse in the sprite without clicking it fires and sets clicktomove to false