playMaker

Author Topic: Rotation Formation  (Read 1252 times)

Athin

  • Full Member
  • ***
  • Posts: 163
Rotation Formation
« on: December 16, 2018, 08:07:59 AM »
Hey everyone.

Hoping to get some help with this one.  I'm currently working with groups of units that I want to line up into a formation (Think like RTS total war style).  I've currently got it semi working but need help to figure out how to handle the actual rotation on the formation.

Currently I have a manager that has all the units selected in an array.  I use that array to line up my guys.  Ex First unit goes exactly where I select, second unit goes to the location I select but also adds his array index to the location target ( adds 1 to X). It works fine like that but they always line up looking north this way.  What I want to do is add in the effect of them off setting depending on the angle from their current location to my selected spot.

I've found Get Angle to Target action and I know this will be what I want but I'm not sure how to use it to get my result.  Any help would be greatly appreciated!

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Rotation Formation
« Reply #1 on: December 17, 2018, 01:21:27 AM »
Hi,

you can rotate around an arbitrary point using RotateAround action.

 but likely it will be a lot easier if you parent your units to a dummy group, then you move each unit in local space, and you can control the global position and rotation using the dummy group. that would be how I handle it, else I would go with an OOP, where each unit control itself, but that's a lot more complex to setup.

Bye,

 Jean

Athin

  • Full Member
  • ***
  • Posts: 163
Re: Rotation Formation
« Reply #2 on: December 17, 2018, 05:53:47 AM »
Hey Jean,

Currently right now I got each unit controlling its own movement since the groups and formations will be a bit dynamic (Players merging/splitting groups).  When I select the group, all the units listen to the next click to use as their destination and offset themselves depending on their index in the array.

I'm really close to the solution but I'm struggling with the math part currently.  I have a Get Mouse X/Y normalized position when a player selects a place for the units to go to. I then subtract .5 from each X/Y variable.  Then I use a multiply operation on each units array index to help offset from the pick location. 

This works to an extent but they crowd on each other when I click near the middle of the screen. They also seem to assemble in the wrong direction (Clicking straight up makes them form a straight line top to bottm rather then left to right.  Also clicking top left has them lining up NE to SW rather then SE to NW like intented)

I'm bashing my head against the wall dealing with the math here so any help would be appreciated.  If I get the solution I'll update this post as well.

Thanks all.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Rotation Formation
« Reply #3 on: December 19, 2018, 12:32:59 AM »
Hi,

 you'll need to be smart with this, else it will be a nightmare ( with or without PlayMaker...)

I would definitly group ennemies for easier formation movement, and then switch to an OOP strategy for each ennemy so that they are independat, and not rely on a manager looping through them, they can still be controlled but by sending events to them ( vis their group parent, which is another convenient benefit for grouping them)

Bye,

 Jean