|
|
|
|
Reply From: |
jgodfrey |
The details of actually doing the things you mention (telekenesis, electro-bolt, …) are too broad for this message. However, for basic management of the mouse, I’d suggest using some sort of global mouse_state
variable that indicates which state the mouse is currently in via a set of appropriate enum
values. So, something like:
# create appropriate mouse states
enum mouse_states { NORMAL, TELEKENESIS, ELECTRO_BOLT, ..., ..., ... }
Then, when the number 1-4 keys are pressed on the keyboard, update some global mouse state variable to track the current state. You could even assign some named keyboard actions to your 4 number keys.
var mouse_state = mouse_states.NORMAL
func _process(delta):
if Input.is_action_just_pressed("telekenesis"):
mouse_state = mouse_states.TELEKENESIS
elif Input.is_action_just_pressed("electrobolt"):
mouse_state = mouse_states.ELECTRO_BOLT
...
...
Then, in your various functions to handle the “powers”, you’d just need to verify that the mouse is in correct mode for a given power. So, something like:
func do_telekenesis():
if mouse_state != mouse_states.TELEKENESIS: return
# do telekenesis stuff here...
This all makes perfect sense to me and i can’t see why it shouldn’t work, but something does’t seem to work.
Did this:
enum mouse_power_state { NORMAL, TK }
var mouse_state = mouse_power_state.NORMAL
Currently i have this here to set the mouse to the right mode:
func _process(delta):
if Input.is_action_just_pressed("ui_up"):
mouse_state = mouse_power_state.TK
Then below as a test i have this section of code:
func _do_tk():
if mouse_state != mouse_power_state.TK: return
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
The idea being that if i press up the overall result should be the mouse cursor disappearing to test this section of code, yet nothing happens when i press up.
matt_day | 2020-05-11 16:14
How / where does _do_tk()
get called? Also, the posted _do_tk()
function body isn’t properly indented (at least as posted).
jgodfrey | 2020-05-11 16:33
Lmao im gonna sound like such an idiot but i commented it out and only just realised ._.
All works fine now ive un-commented it
matt_day | 2020-05-11 16:46