r/construct • • 5d ago

How do i make sprites form a formation

One option for rts games is to have colission and make a moshpit of units, but that tanks performance.'

Is there a simple way to make all units form a array (like nestled lists in programming), so that they all wont move to the same exact spot

Thank You

1 Upvotes

2 comments sorted by

1

u/CalebBennetts 5d ago

This is a real tricky issue (and one I'm personally playing around with right now).

First thing you could do is make a "path group" so the units try to spread out a little. This hasn't had a whole lot of impact in my experience, but it's a built-in feature and easy to implement. Something like,
On right mouse button -> start path group
For each selected unit -> find path to mouse.x,mouse.y
Every tick -> end path group

1

u/lohborn 5d ago

I am not sure exactly what you are going for but you could do something like this:

One leader unit has actual path tracing. Every other unit gets an OffsetX and OffsetY from the leader.

OtherUnit.X = Leader.X + Self.OffsetX*cos(Leader.angle) + Self.OffsetY*sin(Leader.angle)
OtherUnit.Y + Leader.Y + Self.OffsetY*cos(Leader.angle) + Self.OffsetX*sin(Leader.angle)

This assumes the OffsetX and OffsetY are set for when the leader is facing angle=0.