0 votes

I am making a first person shooter where your primary weapon is throwing knives.
I am having trouble with Input.isactionjust_pressed().
I added a feature where right click flips the knife, causing it to be thrown by the blade.
Problem is I want the right click to reverse the process (flipping the knife back to the hilt) in the event of another right click and I have no idea how!
Where it stands now, I right click once, and the knife is stuck in the held by the blade position.

Godot version 3.3.2
in Engine by (31 points)

1 Answer

+1 vote

For this you need to declare a bool variable which will be true for knife and false for blade and hence it will go like this

var knife = true
func _process(delta):
    if  Input.is_action_just_pressed("attack"):
        if knife == true:
            #knife attack goes here
        elif knife == false:
            #blade attack goes here
    if input.is_action_just_pressed("right_click")
        knife = !knife

in the last we equated knife with its reverse. And hence we need not to write multiple if statements.

by (884 points)

Thanks a bunch!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.