Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | BoiTrek |
I want to have a toggle button that when toggled on, the player starts to move right, and when toggled off, the player stops moving. I put a signal on a check button node and connected it to my player kinematicbody2D. This is the code inside it:
var velocity = Vector2()
var speed = 300
const FLOOR = Vector2(0, -1)
func _on_CheckButton_toggled(button_pressed):
if(button_pressed):
velocity.x = speed
$AnimatedSprite.play(“Run”)
else:
velocity.x = 0
$AnimatedSprite.play(“Idle”)
velocity = move_and_slide(velocity, FLOOR)
When I go into the game and toggle the button to on, the player moves once and stops moving. I don’t know what’s causing this to happen. I’m a beginner and I’m probably not noticing something I should.