- Edited
Hi everybody, Juste started to explore godot yesterday (i come from unity) and i'm trying to get a smooth four direction grid based movement kind like rpg maker does but when my camera follow my character the movement sutter a little bit. So i' got a :
TileMap Grid
Ysort
Player
Tween
Sprite
Camera2D
Background Sprite
One thing that i find strange is that if my camera is the last child in player, the player will always be well centered with the camera but if it's not the last child, the player will shake a little bit. Camera have no smooth or margin (always make it worst)
Here is the code i attached to my player
extends Node2D
var grid
var direction = Vector2()
export(float) var speed =5
func _ready():
grid = get_parent().get_parent()
speed = 1.0/speed
func _physics_process(delta):
direction = _get_four_directions()
if direction!=Vector2():
_move_player()
func _move_player():
set_physics_process(false)
var target = position + grid.get_cell_size()*direction
$Tween.interpolate_property(self, "position", position, target, speed, Tween.TRANS_LINEAR, Tween.EASE_IN)
$Tween.start()
yield($Tween, "tween_completed")
set_physics_process(true)
func _get_four_directions():
if Input.is_action_pressed("ui_right"):
return Vector2(1,0)
if Input.is_action_pressed("ui_left"):
return Vector2(-1,0)
if Input.is_action_pressed("ui_up"):
return Vector2(0,-1)
if Input.is_action_pressed("ui_down"):
return Vector2(0,1)
else:
return Vector2()
So do you have a idea why my movement seem to sutter ? Is it something from my code or something from my camera ?