#On/Off switch using keys

8 messages · Page 1 of 1 (latest)

weary ibex
#

I want to rotate the windmill on press of a key and just keep it playing, even if I'm not pressing the key

And If I press it again, it will stop rotating

Currently, I'm using this:
func _physics_process(delta):
rotate_z(0.01)

I tried:

var isRotate: bool = false
func _physics_process(delta):
if Input.is_action_pressed("off") and isRotate:
rotate_z(0)
else:
rotate_z(0.01)

thank you for anyone who is willing to help!

gentle hornet
#

Like an on off switch? I press on once and it spins until I press off?

gentle hornet
#

Then make it so that when you press on, the isRotating gets set to true, and when you press off it get sets to false

#

Then simply check if isRotating == true: and if it is spin the windmill

near widget
#

I would create a function which make rotation happen, maybe :

func rotate_windmill():
  if isRotate: # when isRotate is true
    rotate_z += 0.01 # add 0.01 to rotate_z value

Somewhere in _input(event):

func _input(event):
  if event.is_action_pressed(interact): # a more generic action name, so you can use it for on and off without confusion
    isRotate = !isRotate # if isRotate is true it going to become false and viceversa

and call rotate_windmill in _physics_process(delta)

#

(Sorry, those comments make it ugly)

weary ibex