![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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