HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to make a project move Sin like?

08-09-2009, 09:50 PM#1
Flame_Phoenix
Hi guys, I am making another sample for my newest system CMS and I want to demonstrate how a user can easily create his/her own movement method for the projectile.
For this case I want to make a fire bolt move in a Sin like pattern.
I tried studying Anitarf's submission on a spell contest but my map gives a fatal error and dies ...

Can anyone please help me with this movement formula?
08-09-2009, 11:33 PM#2
chobibo
Wait, I'm still testing if my formula works.

EDIT: nope it doesn't lol.
08-09-2009, 11:48 PM#3
Zerzax
I'll tell you everything, lemme just edit the post:

Okay, so you want to move a projectile in the pattern of a sin wave. The first object is to move linearly between your start and end point (or in the direction of the end point). The easiest way I know of that works with the sin wave is using polar projections. This way, once you've reached a certain point on this line, you can then add or subtract 90 from the projected angle and then project by your distance. If you look at a sin graph, it will show you that the height of the wave is equal to the amplitude of the wave times the sine of the angle. This angle at any time can be determined by dividing your accumulated distance along the line by the wavelength of the wave, then multiplying this value as a factor by 2pi or 360. Once you have the distance, you just add that times the sin / cos of your angle + 90.

Here is a formula :

Collapse JASS:
set linearx = currentx + dist * cos(theta)
set lineary = currenty + dist * sin(theta)

set sinx = linearx + sin((current_distance / wavelength) * 2*bj_PI) * amplitude * cos(theta + bj_PI/2)
set siny = lineary + sin((current_distance / wavelength) * 2*bj_PI) * amplitude * sin(theta + bj_PI/2)

08-10-2009, 09:58 AM#4
Flame_Phoenix
Zerzax, about your formula:
Collapse JASS:
set linearx = currentx + dist * cos(theta)

dist = total distance that needs to be done? Or speed of the projectile?

The amplitude is is Radians right?

EDIT EDIT EDIT


Ok, I used your formula, the result is better (the map doesn't crash any longer) but the movement is at least ... disturbing ...
Here is the code of the method:

Collapse JASS:
//this demonstrates how you can make your own move method!
        method costumMoveMissile takes nothing returns nothing
            local real x = GetUnitX(.currentTarget)-.missile.x
            local real y = GetUnitY(.currentTarget)-.missile.y
            local real distance = SquareRoot(x*x + y*y)
            local real angle1 = Atan2(y, x)
            
            local real linearX = .missile.x + .speed * Cos(angle1)
            local real linearY = .missile.y + .speed * Sin(angle1)
            local real sinX = linearX + Sin((.missileCurrentDist / .targetDistance) * 2*bj_PI) * 25 * Cos(angle1 + bj_PI/2)
            local real sinY = linearY + Sin((.missileCurrentDist / .targetDistance) * 2*bj_PI) * 25 * Sin(angle1 + bj_PI/2)
            
            set .missileCurrentDist = .missileCurrentDist + distance
            
            set .missile.xyangle = angle1
            set .missile.x = sinX
            set .missile.y = sinY 
        endmethod

If you need to know more, here is the code of the spell:
Expand JASS:

Can some one please tell me what I am doing wrong ?
08-10-2009, 12:58 PM#5
Tot
can you post a screenshot when it's moving
Quote:
disturbing
?

cause I had a similiar problem in the first version of my contest spell
08-10-2009, 03:26 PM#6
Mr_Saturn
Quote:
Originally Posted by Flame_Phoenix
Can some one please tell me what I am doing wrong?
Quote:
Originally Posted by Zerzax
The first object is to move linearly between your start and end point (or in the direction of the end point).... This way, once you've reached a certain point on this line, you can then add or subtract 90 from the projected angle and then project by your distance.

Also,
Collapse JASS:
set .missileCurrentDist = .missileCurrentDist + distance
wtf
08-10-2009, 03:31 PM#7
Vexorian
The mystery here is, if you want it to know like Sin function, how about you use Sin ?
08-10-2009, 07:19 PM#8
Flame_Phoenix
Saturn:
1 - So first I need set missile.x = linearX and then missile.x = sinX?
2 - I don't get it, why is it wrong? That is the current distance between the target and the missile ...Mmmm, I will think about it
Quote:
The mystery here is, if you want it to know like Sin function, how about you use Sin ?
Wermmm, I am using Sin ...
08-10-2009, 07:26 PM#9
Pyrogasm
...and you're retarded.

Collapse JASS:
set data.dist = data.dist+data.inc
set data.x = data.startx + data.dist*data.cos
set data.y = data.starty + data.dist*data.sin

set data.sindist = Sin(data.dist/data.period)*data.amp

set data.x = data.x + data.sindist*data.vertcos
set data.y = data.y + data.sindist*data.vertsin
.period affects the wavelength of the sine waves, and .amp affects the height; store all the static Cos() and Sin() computations before you start and you'll save a lot of function calls.

You could even condense it further:
Collapse JASS:
set data.dist = data.dist+data.inc
set data.sindist = Sin(data.dist/data.period)*data.amp
set data.x = data.startx + data.dist*data.cos + data.sindist*data.vertcos
set data.y = data.starty + data.dist*data.sin + data.sindist*data.vertsin
08-10-2009, 09:17 PM#10
Flame_Phoenix
Hi Pyro, I want you to meet my friend Mr.Nice:
Quote:
Flame_Phoenix(FP): Hi there Mr.Nice, what's up?
Mr.Nice(MN): hey there flame, today I am here to talk about Pyro... did you read his last comment?
FP: ya ... not much nice ..
MN: the topic I will teach him is "Good manners" or "how to talk to people nicely"
FP: I think that is exaggerating... he is nice, he is just really pissed at me because I never can understand the Sin formulas and many people already tried to help me
MN: people are different, therefore they have different problems and understand different things with different levels of difficulty. That is not a reason to act like a moron or like an idiot.
FP: True, but he can't understand that ...
MN: Obviously he doesn't understand and by his comments he doesn't want to understand... everyone in wc3c knows that you have problems with maths ... see that Plane spell ? or that new system CMSomething?
FP: ... the Vjass Bomber ... I bugged Anitarf so much I believe he got tired of me for all eternity ... poor guy ... and it is Chain Missile System not something ... ya I know where you are getting, chobibo did all the 3d maths, I only did the 2d and then they were crap in the end ...
MN: If not by chobo I bet you wouldn't make CMS ...
FP: It is chobibo chobo means "noob" is sc2 language ... and yes, you are probably right ...
MN: and now with 2D3S formulas ...
FP: I am getting those ... I just have problems with the xefx module, Anitarf seems to have ideas but he makes very few posts for me to understand them...
MN: anyway back to business, that Pyro guy had lots of chances to understand you have problems with maths ... if doesn't see that then he sure is blind or something...
FP: ... my guess is that he doesn't care ...
MN: Well, he should care, because he is being a bastard by insulting you with your own problems. I would like to see his face if you could make fun of one of his personal problems ... I would like to see how he would feel...
FP: People at wc3c aren't good with feelings, they simply ignore them ... see Girffen, per example, could you talk to him?
MN: Hey hey hey, what do I look like? Mr.Jesus ? I don't think so. Everyone knows that guy is lost, I am not wasting my time with him neither would Jesus not madre Theresa nor Gandhi nor whatever, they would just probably kick his ass and so would I.
FP: Jesus ... that's not very nice ...
MN: Hey, it's just a nickname OK? I said I am not Jesus ffs ...
FP: Anyway, you think you can talk to Pyro?
MN: I am sure that if he is reading this then he already got the main idea ... if not, then he is as lost as Griffen.
FP: will you come back?
MN: Dunno ... I wonder if I should talk to Tot or to someone else ... maybe I will see you again ...
FP: Hope not ... I only post your quotes when people behave badly to me, I hope this doesn't become a habit ...
MN: Makes 2 ... now if you excuse, it's time for Hitler's lesson ...
FP: lol !?
MN: Saddam is here too ...
FP: WTF !?
MN: you would be amazed with the number of jerks this world has ...
FP: seems so ... cya
MN: cya..

Anyway, thx for the post ...

I think I got it ...

Collapse JASS:
//this demonstrates how you can make your own move method!
        method costumMoveMissile takes nothing returns nothing
            local real x = GetUnitX(.currentTarget)-.missile.x
            local real y = GetUnitY(.currentTarget)-.missile.y
            local real distance = SquareRoot(x*x + y*y)
            local real angle1 = Atan2(y, x)
            
            local real linearX = .missile.x + .speed * Cos(angle1)
            local real linearY = .missile.y + .speed * Sin(angle1)
            local real sinX = linearX + Sin((.missileCurrentDist / .targetDistance) * 2*bj_PI) * .amplitude * Cos(angle1 + bj_PI/2)
            local real sinY = linearY + Sin((.missileCurrentDist / .targetDistance) * 2*bj_PI) * .amplitude * Sin(angle1 + bj_PI/2)
            
            set .missileCurrentDist = .missileCurrentDist + .speed
            
            set .missile.xyangle = angle1
            set .missile.x = sinX
            set .missile.y = sinY 
        endmethod

Spell:
Expand JASS:

I can also post testmap is you are curious =D
08-10-2009, 09:35 PM#11
Zerzax
Instead of targetDistance I would use the wave period. Sorry I didn't post further, I've been in class all day.

EDIT: I guess the distance you divide by depends on the frequency or period of the wave. Pyro's code block looks fine.
08-10-2009, 11:25 PM#12
chobibo
I'm chobo, the sc2 noob lol.
08-11-2009, 08:32 AM#13
Flame_Phoenix
Quote:
EDIT: I guess the distance you divide by depends on the frequency or period of the wave. Pyro's code block looks fi
I see... I guess I will now try Pyros's formula. I just don't get what vertcos and vertsin are ...
and I believe the theta I should use us the original angle between targets ? I think so.
I will give a try today.
Quote:
I'm chobo, the sc2 noob lol.
Quote:
It is chobibo
xD
08-11-2009, 12:24 PM#14
Pyrogasm
Sine and Cosine of the vertical angle...

Really, if you understood what it was you were doing you'd understand why the code is what it is and what exactly each part does.

The easiest way to do this is with a double-projection approach where you project the position of the object once first along a line towards the target point, and then use the value of the Sin() function to tell you a vertical distance away from that line.
08-11-2009, 12:52 PM#15
Rising_Dusk
Quote:
Originally Posted by Flame_Phoenix
Hi Pyro, I want you to meet my friend Mr.Nice:
I'm going to give you a hard lesson in life. You're like a puppy; we don't kick the puppy because it is a puppy, but we still feel obliged to yell at the puppy when it forgets how to breathe.

Your problem is not that you don't understand. No, that is the least of your problems. Your problem, Phoenix, is that you are virtually immune to education. One can spend entire threads explaining something to you and yet you can retain conviction that their explanation is somehow wrong or incorrect or flawed. There are examples all over the forums, so I refuse to spend time finding them.

WC3C has a reputation of being the best at helping people; however, that reputation comes at a price. First, you must be able to help yourself. If you cannot help yourself, then God only knows what you expect us to do for you. This question that you ask has been solved thousands of times over the course of WC3C's existence in so many ways that even you can find one that makes sense to you. That this thread exists and that it still hasn't sunk in how to do it are examples of your willingness to waste our time and your lack of desire to learn anything on your own, but rather only learn by having it spoon-fed to you.

And that is the last I'm going to hear of your Mr. Nice crap. If what I just said doesn't make sense to you, angers you, saddens you, or you just don't care about it, then tough luck. Don't act persecuted, because the only one at fault for how you are treated is yourself.