Zigzags

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Jeebus... I cannot get a zigzag to work. I am trying to make a spell that involves moving the caster in a zigzag towards the target location, but, as the level of the spell increases, I want to be able to add more points into the zigzag, making denser... if that makes sense. Any help? Perhaps a method for moving the unit? (I really want to use SetUnitX and SetUnitY, not "move"). I know Pyro made/was working on some spell with a zigzag in it...
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
A basic zigzag function would be (replace global with handle system / strcuts):

JASS:
function zigzag takes nothing returns nothing
local location p= GetUnitLoc(GetTriggerUnit())
local location p2
local real distance = 200.
local real angle = GetUnitFacing(GetTriggerUnit())

if udg_global == 0 then
    set udg_global = 1
    set angle = angle + 90.
else
    set udg_global = 0
    st angle = angle - 90
endif

set p2=PolarProjectionBJ(p,distance,angle)
call SetUnitPositionLoc(p2)
endfunction


Something like that.

Work from there.
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Believe me... I have... and it does not work...

The following code has been JASSed to reduce strain on your eyes...

JASS:
    private function Duration takes integer level returns real
		return 1.5
	endfunction
	
	private function ZigzagPoints takes integer level returns integer
		if(level<3)then
			return 4
		elseif(level<5)then
			return 5
		endif
		return 6
	endfunction
	
	private function Conditions takes nothing returns boolean
		return GetSpellAbilityId()==SpellId
	endfunction
	
	public struct Cache
		unit caster=null
		player owner=null
		timer t=null
		trigger trig=null
		triggeraction trigact=null
		real cx=0.
		real cy=0.
		real ox=0.
		real oy=0.
		real nx=0.
		real ny=0.
		real npx=0.
		real npy=0.
		real tx=0.
		real ty=0.
		real direction=1.
		real cang=.0
		real ang=0.
		real dur=0.
		real cdur=0.
		real mdur=0.
		real seclength=0.
		real speed=0.
		real cos=0.
		real sin=0.
		region map=null
		integer zigcount=0
		integer level=0
		integer points=0
	endstruct
	
	private function Colide takes nothing returns nothing
		local Cache cache=GetStructB(GetTriggeringTrigger())
		//Damage...
	endfunction
	
	private function TimerEnd takes nothing returns nothing
		local Cache cache=GetStructA(GetExpiredTimer())
		set cache.dur=cache.dur+.05
		call SetUnitX(cache.caster,cache.nx)
		call SetUnitY(cache.caster,cache.ny)
		call SetUnitFacing(cache.caster,cache.ang)
		if(cache.dur>=cache.cdur)then //Change Course
			set cache.zigcount=cache.zigcount+1
			set cache.direction=cache.direction*-1.
			set cache.ox=cache.npx
			set cache.oy=cache.npy
			if(cache.zigcount>=cache.points)then //Last Zigzag
				set cache.npx=cache.tx
				set cache.npy=cache.ty
				set cache.cdur=cache.mdur
			else
				set cache.npx=(cache.cx+((cache.seclength*cache.zigcount)-(cache.seclength*.5))*Cos(cache.cang))+Width*(cache.cang+90)*cache.direction //The Zigpoint X
				set cache.npy=(cache.cy+((cache.seclength*cache.zigcount)-(cache.seclength*.5))*Sin(cache.cang))+Width*(cache.cang+90)*cache.direction //The Zigpoint Y
				set cache.cdur=((cache.mdur/cache.points)*cache.zigcount)-((cache.mdur/cache.points)*.5)
			endif
			set cache.ang=Atan2(cache.npy-cache.oy,cache.npx-cache.ox) //The angle of the current Zig
			set cache.cos=Cos(cache.ang)
			set cache.sin=Sin(cache.ang)
		endif
		//Set New Coords
		set cache.nx=GetUnitX(cache.caster)+cache.speed*cache.cos
		set cache.ny=GetUnitY(cache.caster)+cache.speed*cache.sin
		if(cache.dur>cache.mdur)then //Clean Up
			call PauseTimer(cache.t)
			call ClearStructA(cache.t)
			call DestroyTimer(cache.t)
			call TriggerRemoveAction(cache.trig,cache.trigact)
			call ClearStructB(cache.trig)
			call DestroyTrigger(cache.trig)
			call PauseUnit(cache.caster,false)
			call cache.destroy()
		endif
	endfunction
	
	private function Cast takes nothing returns nothing
		local Cache cache=Cache.create()
		local location tar=GetSpellTargetLoc()
		
		set cache.caster=GetTriggerUnit()
		call PauseUnit(cache.caster,true)
		call IssueImmediateOrder(cache.caster,"stop")
		set cache.owner=GetOwningPlayer(cache.caster)
		set cache.level=GetUnitAbilityLevel(cache.caster,SpellId)
		set cache.points=ZigzagPoints(cache.level)
		set cache.mdur=Duration(cache.level)
		set cache.zigcount=0
		
		set cache.seclength=Length/cache.points //The length along the center line of each section
		set cache.direction=1.              //1 = Left or -1 = Right
		set cache.cx=GetUnitX(cache.caster) //X of caster
		set cache.cy=GetUnitY(cache.caster) //Y of caster
		set cache.ox=cache.cx               //The 'old' X
		set cache.oy=cache.cy               //The 'old' Y
		set cache.tx=GetLocationX(tar)      //'Target' X
		set cache.ty=GetLocationY(tar)      //'Target' Y
		set cache.cang=Atan2(cache.ty-cache.cy,cache.tx-cache.cx) // The center angle
		set cache.npx=(cache.cx+(cache.seclength*.5)*Cos(cache.cang))+Width*(cache.cang+90)*cache.direction //The Zigpoint X
		set cache.npy=(cache.cy+(cache.seclength*.5)*Sin(cache.cang))+Width*(cache.cang+90)*cache.direction //The Zigpoint Y
		set cache.ang=Atan2(cache.npy-cache.oy,cache.npx-cache.ox) //The angle of the current Zig
		set cache.cos=Cos(cache.ang)
		set cache.sin=Sin(cache.ang)
		set cache.cdur=(cache.mdur/cache.points)*.5
		set cache.speed=SquareRoot((cache.ox-cache.npx)*(cache.ox-cache.npx)+(cache.oy-cache.npy)*(cache.oy-cache.npy))/cache.cdur
		set cache.nx=cache.ox+cache.speed*cache.cos //The next X to be moved to
		set cache.ny=cache.oy+cache.speed*cache.sin //The next Y to be moved to
		
		set cache.t=CreateTimer()
		call SetStructA(cache.t,cache)
		set cache.trig=CreateTrigger()
		call SetStructB(cache.trig,cache)
		call TriggerRegisterUnitInRange(cache.trig,cache.caster,ColideRange,Filter(function AlwaysTrue))
		set cache.trigact=TriggerAddAction(cache.trig,function Colide)
		call TimerStart(cache.t,.05,true,function TimerEnd)
		
		call RemoveLocation(tar)
		set tar=null
	endfunction

	//===========================================================================
	public function InitTrig takes nothing returns nothing
		local integer a=0
		set gg_trg_Zigger=CreateTrigger()
		loop
			exitwhen a>11
			call TriggerRegisterPlayerUnitEvent(gg_trg_Zigger,Player(a),EVENT_PLAYER_UNIT_SPELL_EFFECT,Filter(function AlwaysTrue))
			set a=a+1
		endloop
		call TriggerAddCondition(gg_trg_Zigger,Condition(function Conditions))
		call TriggerAddAction(gg_trg_Zigger,function Cast)
	endfunction



As you can (or maybe can't) see, the real problem stems from the fact that I want to be able to dynamically change the number of points along the zigzag, while still keeping the same length. So, the higher the level of the spell, the denser the zigzag.

Code:
Compare :

45 + 90 + 90 + 90 + 45

to

10 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 10

The second would have significantly more points, yet they would both get you the same distance.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Right, since I'm no genius at JASS writing, I'll write it in my own special way (oh gnoes)


Point variables:
- Basepoint1
- Basepoint2
- Startpos
- Endpos
- Temppos
- Movepos

Integer variables:
- ZZPointamount (amount of ZZ points you want (caster/target point not included)
- ZZModifier = 1
- ZZcount

Real variables:
- ZZwidth (= total zigzag width / 2)
- ZZdistance
- CTT_Angle (= CasterToTargetAngle)


Code(ish):

JASS:

constant real ZZwidth = ???? // user defined, keep in mind that this is actually half the width of the entire zigzag spanwidth
constant integer ZZpointamount = ???? // constant, or defined by ability level... your pick really


set Startpos = casting unit
set Endpos = target point/unit
set ZZdistance = distance between Startpos and Endpos
set CTT_Angle = angle between Startpos and Endpos
set Basepoint1 = point at ZZwidth distance of Startpos towards CTT_angle+90°
set Basepoint2 = point at ZZwidth distance of Startpos towards CTT_angle-90°

while (ZZcount < ZZpointamount)
{
    set ZZcount = ZZcount + 1
    set Temppos = point at ZZcount*(ZZdistance/ZZPointamount) distance of Startpos towards CTT_angle
    set Movepos = point at ZZwidth distance of Temppos towards CTT_angle+(ZZmodifier*90°)
    set ZZmodifier = 0 - ZZmodifier
    order unit to move to Movepos
    wait untill unit reaches Movepos
}

order unit to move to Endpos


This should divide the distance between caster and target by the amount of zigzag points you want, then alternate from left to right every time (= why ZZmodifier changed from one to minus one and back all the time) over a width you can set.

Forgive the While loop and crappy JASS, I just started out in it, so I used a bit of pseudo coding left and right ;)

Hope you understand where I'm going with this.
 

martix

There is no spoon
Reaction score
49
Coordinates usually means vector and trigonometry calc's. So this requires you to know your average high-school physics.
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
I can do trig. Its dynamicly generating the points that I'm having issues with. Magentix' method seems good to me. I hadn't though of using a basepoint relate to width. I will try that, and see if I can't get this to work. Thus far, I have only been able to crash the game (I moved my unit out of the map, I presume).
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top