(I am using v.3 and the perspective is top-down)I want to create a "chain" where there would be several collision objects but only the 1st one is controlled by the keyboard/controller and the rest of them fall behind and follow the movements of the first one(Like Badeline from Celeste). I have tried making the different objects follow me individually but they would clump up together and not stay in a line how do I hold them in place? Sorry for any confusing writing
How would I go about making a "snake" where KinematicBody2d's mimic each other's movement?
The way I'd do it would be to store the inputs received by the head of the chain, and pass those inputs with a delay to the next object in the chain. If each object in the chain passed the inputs to the next, I think it should recreate the effect you're talking about.
I think something like this would work:
var head_of_chain = true
var delay = 1.0
var next_obj_in_chain
var input_store = []
func _input(event):
if head_of_chain:
manage_input(event)
func manage_input(event):
if event.is_action_pressed("up"):
up()
elif event.is_action_pressed("down"):
down()
elif event.is_action_pressed("right"):
right()
elif event.is_action_pressed("left"):
left()
input_store.append([event, 0.0])
func _process(delta):
var inputs_to_delete = []
for idx in range(len(input_store)):
input_store[idx][1] += delta
if input_store[idx][1] > delay:
next_obj_in_chain.manage_input(input_store[idx][0])
inputs_to_delete.append(idx)
inputs_to_delete.invert()
for idx in inputs_to_delete:
input_store.remove(idx)
This mostly did the trick but I had to modify It would not be rotated if it was not the "head_of_chain" I'm currently working on making them rotate towards each other now to give a more "snake" feel. Thank you for all the help!
a year later
Megalomaniak added the Godot Help tag .