- Edited
So I have movement controls that I have created, and they do what I want when directly in the script of the child I want to move, but I want to control multiple similar units from their parent script, rather than having script on each child. However, the scrip that I have, which allows for the unit to rotate by 60 degrees and move in the direction that it is facing works only when attached directly to the child. I thought my changes to the code on the parent would have been sufficient but it doesn't seem so.
PROBLEM: So the specific problem is that it will only move left and right with the acceleration and deceleration, which is expected before it turns. However once I rotate my desire would be that it would go in the new rotated direction, however it still only goes left and right. So it moves and rotates, it just doesn't match the direction of its movement to the rotation degree.
Here is the code...
func _process(_delta):
var i = 0
var the_unit = arr_ship[i]
var curr_pos = the_unit.position
if Input.is_action_just_pressed("accelerate"):
the_unit.global_position = curr_pos + Vector2(1,0).rotated(deg_to_rad(rotation_degrees)) * Vector2(128,128)
if Input.is_action_just_pressed("decelerate"):
the_unit.global_position = curr_pos + Vector2(-1,0).rotated(deg_to_rad(rotation_degrees)) * Vector2(128,128)
if Input.is_action_just_pressed("rotate_left"):
the_unit.rotation_degrees -= 60
if Input.is_action_just_pressed("rotate_right"):
the_unit.rotation_degrees += 60