I updated to Godot 3.0 but my it doesn't recognize my input :(

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Noob_Maker

Hi, so I was making an updated version of my project for Godot 3 (partly because I got a brand new laptop) And I generally finished from where I left off (minus the mechanic of jumping off walls) but when ever I run the game to test it, it doesn’t recognize that there are inputs going into it. Maybe it’s because the input system got completely changed in 3.0 so there’s an additional step to do so or that it works differently? I have no clue.

Anyway, here’s the code for the blocks that you should pick up with the mouse:

 extends RigidBody2D

var click = Input.is_action_pressed("ui_select")
var Hover = 0

func _ready():
	set_process_input(true)
	set_physics_process(true)

func _physics_process(delta):
	click  = Input.is_action_pressed("ui_select")
	if click == true and Hover == 1:
		set_pos(get_global_mouse_position())

func _on_box_mouse_entered():
	print("I'm hovering!")
	Hover += 1

func _on_box_mouse_exited():
	print("I'm not hovering anymore!")
	Hover -= 1

And here’s the code for the player. It’s a bit long but because I followed a tutorial to see on how to improve on it (the old version was a bit clunky) and that it’s also a rigidBody2D as well.

extends RigidBody2D

var directional_force = Vector2()
const DIRECTION = {
	ZERO  = Vector2(0,0),
	LEFT  = Vector2(-1,0),
	RIGHT = Vector2(1,0),
	UP    = Vector2(0,-1),
	DOWN  = Vector2(0,1)
}
var acceleration = 100
var top_move_speed = 600
var top_jump_speed = 400
#contols
var jump = Input.is_action_pressed("ui_up")
var left = Input.is_action_pressed("ui_left")
var right = Input.is_action_pressed("ui_right")
var down = Input.is_action_pressed("ui_down")

func _ready():
	set_process_input(true)

func _intergrated_forces(state):
	var final_force = Vector2()
	directional_force = DIRECTION.ZERO
	apply_force(state)
	final_force = state.get_linear_velocity() + (directional_force * acceleration)
	if final_force.x > top_move_speed:
		final_force.x = top_move_speed
	if final_force.x < -top_move_speed:
		final_force.x = -top_move_speed
	if final_force.y > top_jump_speed:
		final_force.y = top_jump_speed
	if final_force.y < -top_jump_speed:
		final_force.y = -top_jump_speed
	state.set_linear_velocity(final_force)
func apply_force(state):
	if left == true:
		directional_force += DIRECTION.LEFT
	if right == true:
		directional_force += DIRECTION.RIGHT
	if jump == true:
		directional_force += DIRECTION.UP
:bust_in_silhouette: Reply From: lulu

I noticed that you have to make a variable with input every time when input is called, I mean when there is Input, you must make a variable to handle it, like:

func _process(delta): #or _input(event), read the docs
   var some_input = Input.is_action_just_pressed("ui_accept")
   if some_input:
   #some stuff

or just without var

func _process(delta):
   if Input.is_action_just_pressed("ui_accept"):
    #some stuff

Moreover, if you call Input, you don’t need to set_process_input(true), only when enabling disabled input and vice versa.

aaaaaaaaaaaaaaaaaaaaaa

Thank you for recognizing my mistake

Noob_Maker | 2018-03-25 19:51

Still no response ;^;

Noob_Maker | 2018-03-25 19:53

If you can put your current code somewhere it will be wonderful. I found one more problem with your code, you are using set_pos, this one is not available in Godot 3, now it’s set_position()

lulu | 2018-03-25 20:07

K, here the updated player code. I attempted to use the _input function but no results. I even made it so that the input map had nothing to do with it.

extends RigidBody2D

var directional_force = Vector2()
const DIRECTION = {
	ZERO  = Vector2(0,0),
	LEFT  = Vector2(-1,0),
	RIGHT = Vector2(1,0),
	UP    = Vector2(0,-1),
	DOWN  = Vector2(0,1)
}
var acceleration = 100
var top_move_speed = 600
var top_jump_speed = 400
#contols
func _input(event):
	if event.type == InputEvent.KEY:
		if event.scancode == KEY_D:
			if event.is_pressed():
				directional_force = DIRECTION.RIGHT

func _ready():
	set_process_input(true)
	set_process(true)
func _intergrate_forces(state):
	var final_force = Vector2()
	directional_force = DIRECTION.ZERO
	apply_force(state)
	final_force = state.get_linear_velocity() + (directional_force * acceleration)
	if final_force.x > top_move_speed:
		final_force.x = top_move_speed
	if final_force.x < -top_move_speed:
		final_force.x = -top_move_speed
	if final_force.y > top_jump_speed:
		final_force.y = top_jump_speed
	if final_force.y < -top_jump_speed:
		final_force.y = -top_jump_speed
	state.set_linear_velocity(final_force)
func _process(delta):
	pass

But thank you for the set_position() thing
EDIT: it doesn’t recognize scancode ;^;

Noob_Maker | 2018-03-25 21:39

I would do it like that:

func _input(event):
	if Input.is_key_pressed(KEY_D):
		directional_force = DIRECTION.RIGHT

sorry but i didn’t use to work with events in _input or rigidbody2d, so i can’t help with it.

lulu | 2018-03-25 22:28

Here’s what I got:
Thanks for simplifying the input stuff and I added in print statements to check if it gets the inputs, and it does. The thing is it doesn’t move. I even lowered the weight for the player.
Because of this I’m now wondering why it doesn’t print for the clickable box…Probably something to do with the signals…

Noob_Maker | 2018-03-25 23:02

You have to connect it visually by inspector or connect it by code like this:

button.connect("mouse_entered", self, "name_of_func")

then you must make a function named like name_of_func

lulu | 2018-03-26 08:46

:bust_in_silhouette: Reply From: Bartosz

You are checking inputs only once, you need to either implement _input method and process inputs or pull input state

so…put the input variables in the _input function and repeat them in the other functions or?

Noob_Maker | 2018-03-25 19:35