I'm working with the _input function but it doesn't recognize scancode

Noob_MakerNoob_Maker Posts: 2Member

Hello, I have been working on my project and I have came with a bizarre issue: Godot does not recognize any inputs WHAT SO EVER. At first I was wondering that the inputs had changed in godot 3.0 and so I decided to use the _input. I copied the actions from the input map and nothing happens when I press the keys. Then I made it so that it ignores the input map and just focusing on the key and it didn't recognize KEY, scancode and unicode. What makes this issue even bizarre is that it did recognize KEY_D, the key that I assigned it to move to the righ and when I ran the templates for the plat former it recognized the input. So, I have no idea.
Also, when it didn't recognize the scancode or unicode it thinks I'm talking about mouse buttons for some weird reason.

Here's the code

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.unicode == KEY_D:
        if event.is_pressed():
            directional_force = DIRECTION.RIGHT
    if event.unicode == KEY_A:
        if event.is_pressed():
            directional_force = DIRECTION.LEFT
    if event.unicode == KEY_SPACE:
        if event.is_pressed():
            directional_force = DIRECTION.UP
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
Tagged:

Tags :

Answers

  • kryzmakkryzmak Posts: 66Member
    Answer ✓

    First of all: In Godot v3 _input() and _process() are on by default. Your _ready() code is therefore redundant.

    To your issue: Does this code snippet work?

    func _input(event):
        if Input.is_key_pressed(KEY_D) and event.is_pressed():
            directional_force = DIRECTION.RIGHT
  • Noob_MakerNoob_Maker Posts: 2Member

    Yes this answers my question but the odd thing is that it doesn't move. Maybe I'm not applying enough force...

  • kryzmakkryzmak Posts: 66Member

    I may be wrong but there is no apply_force() method in PhysicsDirectBodyState. Do you mean add_force()? In that case you have to call it with state.add_force().

Sign In or Register to comment.