Looking for examples that aren't plagued by the one issue I'm having with this. Everything works fine, inlcuding being able to move in all 8 directions, except:
Input using two directional keys, let's say Up & Down, isn't always simultaneous. In my testing, one of the keys gets registered before the second key 99% of the time. It's a millisecond difference usually, but since I'm doing grid-based movement, this always results in a 4-drectional movement (either U/D/L/R) followed by the intended direction.
I'm not sure if there's an elegant way to hold off moving for 10ms to wait for a second keypress, or to ignore a few inputs and then grab the next one. Any advice would be appreciated.
onready var vLevelGridObjects = get_node_or_null("../../LevelGridObjects")
var vMoveSpeed = .3
var vDirection = Vector2(1, 0)
var vSelf = self
var vTween = "Player/PlayerTween"
func _process(_delta):
if Input.is_action_just_released("iPlayerInteract"):
vLevelGridObjects._ActorInteract(vDirection)
elif _GetInputDirection() != Vector2(0,0):
vDirection = _GetInputDirection()
vLevelGridObjects._ActorMove(vSelf, vTween, vDirection, vMoveSpeed)
func _GetInputDirection():
return Vector2(Input.get_action_strength("iPlayerRight") - Input.get_action_strength("iPlayerLeft"), Input.get_action_strength("iPlayerDown") - Input.get_action_strength("iPlayerUp"))
----Second attempt----
extends KinematicBody2D
onready var vLevelGridObjects = get_node_or_null("../../LevelGridCollision")
var vMoveSpeed = .25
var vDirection = Vector2(1, 0)
var vReady = 7
var vSelf = self
var vTween = "Player/PlayerTween"
func _process(_delta):
print(str(vReady))
if Input.is_action_just_released("iPlayerInteract"):
vLevelGridObjects._ActorInteract(vDirection)
elif _GetInputDirection() != Vector2(0,0):
if vReady == 0:
vReady = 7
vDirection = _GetInputDirection()
vLevelGridObjects._ActorMove(vSelf, vTween, vDirection, vMoveSpeed)
vReady = vReady - 1
func _GetInputDirection():
return Vector2(Input.get_action_strength("iPlayerRight") - Input.get_action_strength("iPlayerLeft"), Input.get_action_strength("iPlayerDown") - Input.get_action_strength("iPlayerUp"))