Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Elias |
Hi, I am quite new to Godot engine. I have written a simple FPS character (GDScript) according to a yt video. When I press play, I can look around and should be able to move, but if I press anything (even mouse buttons). Then the game freezes and takes no input at all (cant even close the window)
It sounds like you have an error. Is there something in the “Debugger” window?
kidscancode | 2018-10-21 16:28
takes no input at all (cant even close the window)
I’ve had this happen to me before with an accidental infinite loop. Are you detecting input anywhere?
markopolo | 2018-10-22 19:07
its kind of weird it says: Invalid get index “relative” (on base InputEventKey) eventhough i have made an if to make sure it is the mouse moving and not the keyboard pressing that triggers the get of “relative”. If i understand right “relative” is a variable in the function handling mouse input? Anyway I found out that the error only occurs in editor. If i run the project from the project browser it works completely fine. Do you have any idea why? Thanks for very quick response.
Elias | 2018-10-24 17:51
Please share your code. It sounds like you’re receiving a key input (all inputs are processed by _input()
). You probably need to check the event type first.
kidscancode | 2018-10-24 18:31
extends KinematicBody
var cameraAngle = 0
var mouseSensitivity = -0.3
var velocity = Vector3()
var direction = Vector3()
const flySpeed = 1
const flyAccel = 4
#######################################################################################################################
func _ready():
# Called when the node is added to the scene for the first time.
# Initialization here
pass
###########################################################################################################################
func _physics_process(delta):
direction = Vector3()
var aim = $Head/Camera.get_camera_transform().basis
if Input.is_action_pressed("moveForward"):
direction -= aim.z
if Input.is_action_pressed("moveBackwards"):
direction += aim.z
if Input.is_action_pressed("moveLeft"):
direction -= aim.x
if Input.is_action_pressed("moveRight"):
direction += aim.x
direction = direction.normalized()
var target = direction * flySpeed
velocity = velocity.linear_interpolate(target, flyAccel)
move_and_slide(velocity)
#############################################################################################################################
#Handles Mouse Input
func _input(event):
if event is InputEventMouseMotion:
$Head.rotate_y(deg2rad(event.relative.x * mouseSensitivity))
var change = event.relative.y * mouseSensitivity
if change + cameraAngle < 90 and change + cameraAngle > -90:
$Head/Camera.rotate_x(deg2rad(change))
cameraAngle += change
else:
pass
Elias | 2018-10-24 20:45