Recreation Growth Stack Change is a query and reply website for skilled and impartial recreation builders. It solely takes a minute to enroll.
Anyone can ask a query
Anyone can reply
The very best solutions are voted up and rise to the highest
Requested
Seen
11 occasions
I’m making an attempt to spawn sufficient gameobjects(ropePieces) between two level form of like a rope.
However IDK easy methods to cease when i attain the top level
extends Node
onready var rb=$RigidBody2D
onready var begin=$StaticBody2D
onready var finish=$StaticBody2D2
var piece= preload("res://scenes/RopePiece.tscn")
var isStop=false
onready var obj2=$StaticBody2D
func _ready():
for n in 5:
var obj=piece.occasion()
add_child(obj)
obj.place=obj2.place
obj.place.y+=30
obj.get_node("PinJoint2D").node_a=obj2.get_node(".").get_path()
obj.get_node("PinJoint2D").node_b=obj.get_node(".").get_path()
obj2=obj
var distance=obj2.position-obj.place
print(distance)
$endgroup$
What I see is that you’re advancing 30 pixels per object:
obj.place.y+=30
If that’s the area one object must take, and you’ll divide the whole distance by 30 and that ought to provide the variety of objects. One thing like this:
var complete = ceil(begin.place.distance_to(finish.place) / 30)
Then use that to iterate (for n in complete: #…
).
$endgroup$
You should log in to reply this query.
Not the reply you are in search of? Browse different questions tagged .
default