0 votes

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
in Engine by (83 points)

2 Answers

+1 vote
Best answer

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 setprocessinput(true), only when enabling disabled input and vice versa.

by (96 points)
selected by

aaaaaaaaaaaaaaaaaaaaaa

Thank you for recognizing my mistake

Still no response ;^;

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()

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 ;^;

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.

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...

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 nameoffunc

0 votes

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

by (1,022 points)

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

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.