hi there,
i have a unit scene built with components, so i need my characterbody2d, which is responsible for the movement, to be a child of unit. tree looks like this:
Unit (parent)
- CharacterBody2D (child, script attached)
- other components
characterbody2d script:
@export var movement_speed : float
@export var movement_acceleration : float
func _physics_process(delta):
if get_parent().is_in_group("Player"):
velocity = lerp(velocity, get_input() * movement_speed, movement_acceleration * delta)
move_and_slide()
func get_input():
input.x = Input.get_action_strength("Right") - Input.get_action_strength("Left")
input.y = Input.get_action_strength("Down") - Input.get_action_strength("Up")
return input.normalized()
for now, only the characterbody2d moves, but not the whole scene. i need the unit to move along with characterbody2d.
so i added
get_parent().position += velocity * delta
after move_and_slide() but results in different movement. while characterbody2d and unit are same position at start, as soon as i move, the characterbody2d moves away (faster) for some reason. i can see that because i enabled visible collision shapes.
why and how could i fix that?