Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TKT |
func _input(event):
if(Input.is_action_pressed("ui_up")):
if((direction*-1==Vector2(0,-1))):
return;
else:direction=Vector2(0,-1)
elif(Input.is_action_pressed("ui_down")):
if(direction*-1==Vector2(0,1)):
return;
else:direction=Vector2(0,1)
elif(Input.is_action_pressed("ui_left")):
if(direction*-1==Vector2(-1,0)):
return;
else:direction=Vector2(-1,0)
elif(Input.is_action_pressed("ui_right")):
if(direction*-1==Vector2(1,0)):
return;
else:direction=Vector2(1,0)
if event is InputEventKey and event.pressed:
gameStarted=true;
in phyiscs process(delta):
if gameStarted:
checkborders()
move_snake()
head_collision()
move snake funct:
func move_snake():
previousHeadPos = pix2grid(get_node("head").position)
get_node("head").position += direction*scl
Inputs controlling if previous direction opposite of the current direction. If its true dont change direction. However when i looked at the print of consecutive directions they can become opposite of each other.I checked(print) them at move snake function. If i press Left,top,down fastly it breaks the rule . How will i prevent user to make opposite direction press and ignore them.