Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Sanctumm |
Heya guys. I am totally new to coding but want to get started in it. Ive seen alot of tutorials lately and want to work on a basic Tile style game where i can just roam aorund.
My question is - How do i get mouse to work for normal click and move
i get get it to work when working on a sprite node but it just summons there asap id like to get a click and walk/run to clicked area.
Cant get any mouse click to work in KinematicBody2d even tho im following the basic tutorials
extends KinematicBody2D
export (int) var speed = 200
var target = Vector2()
var velocity = Vector2()
func _input(event):
if event.is_action_pressed(‘click’):
target = get_global_mouse_position()
func _physics_process(delta):
velocity = (target - position).normalized() * speed
# rotation = velocity.angle()
if (target - position).length() > 5:
velocity = move_and_slide(velocity)
!Above doesnt work… Any idears?
Buttom one is what i got to work for now but its for a sprite :
extends Sprite
func _process(delta):
if(Input.is_key_pressed(KEY_A)):
self.position.x-= 1
if(Input.is_key_pressed(KEY_D)):
self.position.x+= 1
if(Input.is_key_pressed(KEY_W)):
self.position.y-= 1
if(Input.is_key_pressed(KEY_S)):
self.position.y+= 1
#Quit on Q press
if(Input.is_key_pressed(KEY_Q)):
get_tree().quit()
#Check for mouse movement
if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
self.position = get_viewport().get_mouse_position()