• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Can we have a compilation of math functions?

Status
Not open for further replies.
Level 9
Joined
May 28, 2007
Messages
365
I've been asking this for a while and never get concise answers. I want to know how to do the following things. I just want a formula, like PolarProjectionBJ

x = # + # * Cos(#)

How do I make a projectile move in a Sin wave? (meaning it goes up and down).
How do I make a spiral effect?

I just want the formulas for these 2 things.
 
Level 9
Joined
May 22, 2009
Messages
276
I don't think you really need a formula, the editor can use Sin and Cos

I've looked the sinusfunction up in my math syllabus, I'm guessing you can move your projectile giving the cordinates [Integer A, Sin(Integer A)], with [0,0] being the position of the caster, even tho I'm not very sure of this, I'll test it out.
 
Level 9
Joined
May 22, 2009
Messages
276
ok I tried it and failed horribly, maybe I have to use 360° instead of 2Pi, but I didn't get much out of it

But anyway, if you want to make a spiral, u can easily make an infinity looking one (8 but horizontal)
 
and if that is too complicated for you just look at that:

  • Events
    • Time - Every 0.03 seconds of game time
  • Conditions
  • Actions
    • Set a = (a + 3.00)
    • Set x = (300.00 x (Cos(a)))
    • Set y = (300.00 x (Sin(a)))
    • Custom script: call SetUnitX(udg_u, udg_x)
    • Custom script: call SetUnitY(udg_u, udg_y)
    • Set heightangle = (heightangle + 20.00)
  • ___________________________________________________
    • This is the important part
    • Set r = (((Sin(heightangle)) x 200.00) + 200.00)
  • ___________________________________________________
    • Animation - Change u flying height to r at 0.00
a sinus wave has values from 0 to 1 to 0 to -1 and back to 0 so you will have to multiplikate it with some value to see any difference
and since you can't have negative height you will have to add something so the unit wont bounce against the ground...stay there for some time...and come back
 

Attachments

  • test.w3x
    12.4 KB · Views: 54
Level 9
Joined
May 28, 2007
Messages
365
sin
x= a + b * cos(phi) +sin(theta)*d
y= a + b * sin(phi) +sin(theta)*d

no?

spiral
x=a+b*cos(phi)
y=a+b*sin(phi)
phi=phi+pi/8
b=b+5

I think your along the right track for the first one. But could you give me what the values mean and put it in JASS syntax so I can understand it better.

What is a, what is b, what is d
What is theta, phi?

x = GetUnitX(testUnit) + 1*Cos( GetUnitFacing(testUnit)*bj_DEGTORAD ) + Sin(a) * d

Is what I'm using and getting the unit moving in a HUGE sine wave, the size of the map.

EDIT:
I figured it out.

JASS:
function SinProjectionX takes real x, real dist, real angle returns real
return x + dist*Cos(angle) + Sin( (a variable that increases on each call of this function) )*(amplitude)
endfunction
 
Last edited:
How do I make a projectile move in a Sin wave? (meaning it goes up and down).

So, I can for example, shoot out a rock from my hero and the rock spins from left to right.

please decide

Sin and Cos take radians, not degrees, so I wouldn't add 3 but something like PI/20

The BJ functions take degrees.

JASS:
function SinBJ takes real degrees returns real
    return Sin(degrees * bj_DEGTORAD)
endfunction
 
I think your along the right track for the first one. But could you give me what the values mean and put it in JASS syntax so I can understand it better.

What is a, what is b, what is d
What is theta, phi?

x = GetUnitX(testUnit) + 1*Cos( GetUnitFacing(testUnit)*bj_DEGTORAD ) + Sin(a) * d

Is what I'm using and getting the unit moving in a HUGE sine wave, the size of the map.

EDIT:
I figured it out.

JASS:
function SinProjectionX takes real x, real dist, real angle returns real
return x + dist*Cos(angle) + Sin( (a variable that increases on each call of this function) )*(amplitude)
endfunction

another thing you should know is that a full rotation for a sin curve is 2pi. Now if you want to have a full rotation for the maximum distance you have to change the value that increases with each interval.

distance=distance+speed
theta=(distance/maxDistance)*2Pi
x=x0+speed*cos(direction)+sin(theta)*amplitude

two rotations would be 4pi.

if you want to have a rotation based on time you need to do something like this:

a=1/fps ( timer iterations per second )*t(rotations per second)
save a in a struct real(a)
save q in a struct real(0)

q=q+a
theta=q*2pi ( not quite sure if this is it.. but ohwell got no testmap atm :/ )
 
Status
Not open for further replies.
Top