Formation flying....

Post Reply
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Formation flying....

Post by Brian Beuken »

Ok bit of a general question but I am having a bit of trouble with this...

I have a formation of ships, (the actual formation shapes vary from lines to V's to X's etc)

All the ships are moving via bullet with velocity derived from their forward heading, which in turn is derived from the vector to their target formation slot.

This all works fine, ships effectively home to their formation slot and when in the slot stay there though their initial choice of slot needs more work...once in their slot they proceed along the line fine, until the formation needs to turn.

I have the formation slots controlled by a non physics rig that moves from point to point in space, dragging the slots with it.. but when the formation rig turns with anything more than 10-15 deg angle, I am finding the ships lose their place in the slot, and spin back to find it.. which is not a formation turn.

I can take the slot positions and manually set the ships positions overulling Bullet but that comes out quite jerky and I what I really want are for the ships on the extremes of the wheel or motion to slow, even reverse, or accelerate to stay in their slot.. but its escaping me how to do that, for now.
I have a small video here https://www.patreon.com/posts/55018001

Its important that the ships retain their independence to avoid possible hazards and be able to break out of the formaiton, so I don't want the rig to rigidly overrule bullets movement.

Is there a good way that Bullet can handle a grouping of objects like this?
Im reading more methods on formation movment and getting some good ideas, but bullet needs to be happy with them for them to work and so far I am not getting what I want.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Formation flying....

Post by drleviathan »

I don't think there is a simple way for a core Bullet feature to provide the movement you want. The problem is in your custom control logic and the solution will be to fix it.

It looks to me like your ships only fly forward to get to their target point. Hence, when the target point is behind them they turn around. But the Rig itself has an effective forward velocity and if the ship were to just slow down their target point might catch up to them.

Here is a simple way to to it. Rather than have your ship fly toward its target point's current position you should have it try to achieve a velocity that will bring it to the target's point future location... in the future. In other words:

(1) Chose a characteristic time period that you'd like your ship to reach its target point. It should probably be few seconds. I'll call this the FUTURE_PLANNING_PERIOD.

(2) Use the Rig's current linear and angular velocities to compute the target point's position... FUTURE_PLANNING_PERIOD seconds in the future. Let's call it the FUTURE_TARGET_POSITION.

(3) Do the math to compute the velocity your ship would need to bring it to the FUTURE_TARGET_POSITION in FUTURE_PLANNING_PERIOD seconds.

(4) Rather than slam the velocity of your ship to the result of (3), accelerate toward it. My preferred way to do this is not to apply a force, or to set its gravity just right (an easy way to get uniform acceleration). Instead I like to blend a little bit every frame between the ship's current velocity and its target velocity and to just slam the ship to the blended velocity... capped of course by the ship's limited acceleration capabilities.

You might have to tune your FUTURE_PLANNING_PERIOD to accommodate Rig dimensions and its typical slew rates at the hand of twitchy Players, and you'll have to implement reasonable logic at step (4), but when you're done such an algorithm will provide a much smoother swarm reformation.
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Re: Formation flying....

Post by Brian Beuken »

Yup I understand that concept fine, its how I do some of my intercept systems...so it makes sense, you are right I only allow the ships to do forward motion and lerp to their target heading it creates a more realistic flight charactaristic.

I can certainly work out the future positions of the slots, but that will still result in target points being behind the current position, which creates an exception to the rules I have set... I might freeze the lerp to new heading in favour of a slow manouvere to target position..

yeah force isn't really useful for these kinds of movments all the engines are rear mounted I give them all forward motion with an angular thruster effect, it many not be 100% realistic for space motion but its something the player can grasp.


its a surprisingly tricky thing to do if you don't just plug in the rigs slot positions... But thank you for the advice I will tinker with this.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Formation flying....

Post by drleviathan »

Well... if the Player can drag the Rig around as fast as they want then there is no way to prevent very odd relative displacement between a Ship and its target point. Even with future prediction... ships will struggle to get into formation because the Rig will be unpredictable. This would be synonymous with an inept fleet commander barking unreasonable orders from the flagship: chaos ensues.

Perhaps there should be two Rigs. One for the Player to move around willy-nilly, while the second ponderously tries to follow the first, with some limits as to how fast it can slew. The swarm could follow the second Rig, aiming for their future targets.
Brian Beuken
Posts: 46
Joined: Sat Jul 29, 2017 9:19 pm

Re: Formation flying....

Post by Brian Beuken »

Well there's a couple of things I can do.. for a start the rig needs to pay much more attention to the speed of the objects in the slots... if a turn creates a displacement at the extremes thats too far for the ship to catch, it needs to slow down.... that might work

Also the rig should use the inner ship as a pivot point rather than use its own central position. I like that idea more, but it will make the rigs turns'to points somewhat harder


And less work, the ships should be able to tell the rig to slow down...when it cant keep up. this might make the rig movment less smooth, but of course it won't be visible normally, its only the ships that need to look smooth.


I'll try a few of these ideas in due course, maybe a combination.

Whats clear is that the independant motion of each ship needs to be more focused on the act of making a turn, rather than slavish following the rig which might suggest I can released them to complete a turn then let them play catch up again.... lots of options just got to se which gives the best result.
Post Reply