Making particles move to a point in a radius without using fields

Started by Nicant, May 13, 2017, 12:17:49 PM

Previous topic - Next topic

Nicant

In my next map, i am going to have a weapon that fires black holes at random locations on a map. I am working on the black hole itself first. The black hole pulls in ships just fine, but not particles. So without using fields, i need the particles to go to the point on where the black hole is. To make the particles go to that point, i'm using SetParticleMotion. The problem is finding the Delta X and Y of the angle. Here is the code of the black hole so far:

# --BlackHole-- 5/12/2017 9:24:40 PM

once
Self "main" "Custom2" SetImage
CreateParticle (GetUnitPixelCoordX (Self) GetUnitPixelCoordY (Self) 0 0 3 True) ->Center
SetParticleDrag (<-Center 999)
SetParticleMaxSpeed (<-Center 0)
SetParticleHealth (<-Center 500)
SetParticleMaxAge (<-Center -1)
GetParticlePosition (<-Center) ->px1 ->py1
endonce

GetImageRotation (Self "main") ->Rotation
SetImageRotation (Self "main" add (<-Rotation 0.04)) #Makes BlackHole spin
<-Rotation 6.3 gt if
SetImageRotation (Self "main" 0)
endif

GetNearestShipInRange (CurrentX CurrentY 30 False) ->Ship #Pulls in ships
<-Ship CurrentX CurrentY 1 MoveShip

GetTimer0 eq0 if
GetParticlesInRange (CurrentX CurrentY 30 False True) ->Particles #Finds particles
15 SetTimer0
endif
<-Particles GetListCount 0 do
<-Particles[I] ->Particle #Selects an individual particle
GetParticlePosition (<-Particle) ->px2 ->py2
<-px1 <-px2 sub <-py1 <-py2 sub atan2 ->Angle Trace #Calculates the angle of the Particle in the center with the particle it wants to pull in.
SetParticleMotion (<-Particle #The Delta X and Y of the angle go next, but how do i find them?)
loop


Any help will be appreciated!  :)
CW4 hype!!

GoodMorning

For this, you need basic trig(onometry). I can't add diagrams from this device, so I'll just put in a code snippet.


<-Angle cos <-Distance mul ->DeltaX
<-Angle sin <-Distance mul ->DeltaY


Play with this a little, and you'll see what I mean. Also see that circling script tutorial I wrote some time ago, it has a better explanation.

Edit: Fixed autocorrect error.
A narrative is a lightly-marked path to another reality.

Nicant

Quote from: GoodMorning on May 13, 2017, 07:10:23 PM
For this, you need basic trig(onometry). I can't add diagrams from this device, so I'll just put in a code snippet.


<-Angle cos <-Distance mul ->DeltaX
<-Angle sin <-Distance mul ->DeltaY


Okay with this a little, and you'll see what I mean. Also see that circling script tutorial I wrote some time ago, it has a better explanation.

Thank you! Inserting that with Calculating the distance made it work! I could also use this and try to make a work-around to the queuemove command.(V, if your listening, we need that command! :D )
CW4 hype!!

GoodMorning

We really don't need that command. A list can do it easily enough. If it means that much to you, I can write you a boilerplate script.

Also, w.r.t. SetParticleMotion, there is SetParticlePosition which can help the ends of this script, as can SetParticleImmediateForce.


Edit:

Boilerplate code:


#QueueMove
$Exists:1
once
-?Moves not if
CreateList ->Moves
endif
endonce

<-Moves GetListCount 0 gt if
<-Moves[0] ->TargetX
<-Moves[1] ->TargetY
<-Moves[2] ->Speed

CurrentPixelCoords <-TargetX <-TargetY Distance ->Gap

<-Gap <-Speed lte if
Self <-TargetX <-TargetY SetUnitPixelCoords
<-Moves 2 RemoveListElement
<-Moves 1 RemoveListElement
<-Moves 0 RemoveListElement
else
<-Gap <-Speed div ->Closed #Proportion of distance to terget point traversed

CurrentPixelCoords ->PixelY ->PixelX

<-TargetX <-PixelX sub <-Closed mul ->DiffX
<-TargetY <-PixelY sub <-Closed mul ->DiffY

Self <-PixelX <-DiffX add <-PixelY <-DiffY add SetUnitPixelCoords
endif
endif


#This function should be copy/pasted to other scripts.
:QueueMove #[X Y Speed - ] Queue a move to be made to the specified pixel coordinates at the specified speed.
Self "QueueMove.prpl" "Exists" GetScriptVar not if
Self "QueueMove.prpl" AddScriptToUnit
CreateList ->MoveList
Self "QueueMove.prpl" "Moves" <-MoveList SetScriptVar
else
Self "QueueMove.prpl" "Moves" GetScriptVar ->MoveList
endif

<-MoveList swap PrependToList
<-MoveList swap PrependToList
<-MoveList swap PrependToList


Note: No testing done, but it's a simple enough task that it shouldn't need it.
A narrative is a lightly-marked path to another reality.

Nicant

Can someone delete this comment? I was asking help for another thing but i've gotten it figured out now.
CW4 hype!!