Aiming issue, character keeps moving

Godot Version

Question

in this top down game, I want the player stop moving when he wants to aim and shoot his gun, the problem is, if he is moving and presses the aim button at the same time, the player just moves and doesnt stop. here is the code for movement and aim mechanic:

var aim=false
const max_sp=100
const aimsp=0
var sp=max_sp
enum {IDLE, RUN}
var state=IDLE

func move(delta):
	var input_vector
	if aim==true:
		pass
	if aim==false:
		input_vector = Input.get_vector("ui_left","ui_right","ui_up","ui_down")
		print(input_vector)
		if input_vector==Vector2.ZERO:
			state= IDLE
		else:
			state=RUN
			apply_move(input_vector*Accel*delta)
			blend_pos=input_vector
	move_and_slide()


if Input.is_action_just_pressed("aim"):
		aim=true
		sp=aimsp
		state=IDLE
	if Input.is_action_just_released("aim"):
		aim=false
		sp=max_sp
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and aim==true:
		var dir= get_global_mouse_position()-position
		shoot.emit(position,dir)

Have you tried setting veloctiy = Vector2.ZERO in your action_pressed event

1 Like

thank you… I feel stupid but thank you :rofl:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.