• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Formula help

Status
Not open for further replies.
Level 3
Joined
Sep 9, 2009
Messages
658
I've been trying to solve this for a while now but I can't seem to think of the right way. I need a spell that creates dummy units perpendicular to the caster.

The way I'm going about it is

facing of caster
facing of caster + 270 degrees
facing of caster + 90 degrees

I should be able to create te effects I want perpendicular. But how do I incorporate it into a loop? What formula should I use to get a difference of 270 then 90 on each iteration?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
If he wants to create them in this order(maybe because there is a delay between units?) that won't work.

http://world-editor-tutorials.thehelper.net/formula.php

You can enter values for level 1,2,3 like this:
0 270 450
360 270 450
0 270 90


For first set you have:
(loopInteger*405) - (loopInteger*loopInteger*45)

Edit:Fixed formula as wietlol said.
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I wouldn't use a loop in this scenario at all, in fact I don't see the benefit since the facing + x is constant.

If you ask me there is nothing wrong with doing

facing + 90
do stuff with that
facing - 90
do stuff again

If there are a lot of actions it might be a bit ineffective. In that case I guess I would do something like..
JASS:
// handwritten outside the editor, beware of errors.
local integer i = 90
loop
    exitwhen i == 270
    facing = facing of unit + i
    //do stuff with facing
    set i = 270
endloop
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
-360 should not be doing anything at all...
But on the other hand, yea that should work as well

There is nothing wrong with using it, but in a loop, you can do the stuff for both dummy units with the exact same script.
It makes you make less mistakes when changing your trigger.
 
Level 3
Joined
Sep 9, 2009
Messages
658
@Wietlol were you referring to Chaosy's post? I don't understand what you mean with -360.

@Chaosy Doing it without the loop would be easier but it doesn't sit well with me knowing it's possible with a loop with the right formula. I like the technique of your loop but won't it do two instances instead of three?

@Ceday can you explain your formula more?

Just to clarify, I want to do this with a loop (pretend the degrees are in radians)

JASS:
set facing = GetUnitFacing(u)

set px = x + 100 * Cos(facing + 270)
set px = x + 100 * Cos(facing + 90)
set px = x + 100 * Cos(facing)

call CreateUnit(PlayerId, Dummy, px, py, facing)

EDIT: @Ceday your formula wasn't exactly what I was looking for but I think I got it now with the link you gave. Thanks!
 
Level 12
Joined
Nov 3, 2013
Messages
989
If you're going to make units stand in a line/row to the left & right of the caster or whatever then I'd either do as Chaosy and make two loops, one for left and right direction each, or if you really want only one loop then "facing + (90 * pow( -1, loopInt) )" would work

Odds would be on one side and evens on the other since two negatives makes positives.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Why use power if you can just add 180 multiplied with the loopinteger?

You can just do this:
JASS:
    set facing = GetUnitFacing(u)
    
    set i = 0
    loop
        exitwhen i >= 2
        
        set a = (facing + 90 + 180*i)*bj_DEGTORAD
        set px = x + 100*Cos(a)
        set px = x + 100*Sin(a)
        call CreateUnit(PlayerId, Dummy, px, py, facing)
        
        set i = i +1
    endloop
 
Level 12
Joined
Nov 3, 2013
Messages
989
Why use power if you can just add 180 multiplied with the loopinteger?

Ah, yeah, I didn't think about it. I guess adding 180, 360, 480, etc wasn't as intuitive and just switching between + and - for me, even though it achieves the same here.

My bad :C
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Why do people keep forgetting angles are circular...

What you actually want is caster angle added to -90, 0 and +90. This is a lot easier and more logical since now it increments by 90 each iteration and works for all cases, not just two of them.

JASS:
    // increment by pi/2 radians (90 degrees)
    set increment = bj_PI / 2
    // starting angle converted to radians and offset appropriately
    set angle = GetUnitFacing(u) * bj_DEGTORAD - increment
    // displacement of 100 units
    set displacement = 100

    set i = 0
    loop
        // loop 3 times
        exitwhen i >= 3

        // create unit
        call CreateUnit(PlayerId, Dummy, x + displacement * Cos(angle), y + displacement * Sin(angle), angle * bj_RADTODEG)
        
        // increment angle
        set angle = angle + increment

        // loop increment
        set i = i + 1
    endloop
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
As said before creating units with -90, 0 and +90 angle respectively is not the same thing as 0, -90, +90 if there is a delay between creations.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
As said before creating units with -90, 0 and +90 angle respectively is not the same thing as 0, -90, +90 if there is a delay between creations.
In which case you use an array to feed in the offsets. The array is initialized at map initialization and the offsets are ordered as you desire.

I was under the impression the topic creator wanted the units created instantly at those offsets.
 
Status
Not open for further replies.
Top