Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Newb Gift: Circular Movement (https://forums.graalonline.com/forums/showthread.php?t=39043)

emortylone 10-08-2002 11:13 AM

Newb Gift: Circular Movement
 
It seems that all the newbs seem to have problems for some reason with cos and sin. I feel it is my responsibility then to provide help and give a quick description. I know this has been covered UBER amounts of time (Maybe this'll get stickied even)

First off, Sin is the opposite angle divided by the hypotenuse. Cos is the adjacent angle divided by the hypotenuse. Perhaps Kai will be kind enough to post his chart up again ;) Using sine (sin) is generally applied to the x value. Using cosine(cos) is generally applied to the y value. When moving around persay a light or something, this is the format you would use:
NPC Code:

if (action)
{ x=x+sin(angle)*distance;
y=y+cos(angle)*distance;
}


The x value gets added to the sin of the angle, then multiplied by the distance from the centre point. It isn't all that hard. Play with it a bit. Use a variable for angle and distance. Try and get things to move on a timeout or whatnot. It'll come in handy. I hope you find use for it and I explained what you did not understand. If you have any other questions, that haven't been answered in EVERY other cos/sin thread, ask away.
---Shifter

R0bin 10-08-2002 02:14 PM

Re: Newb Gift: Circular Movement
 
Quote:

Originally posted by emortylone
It seems that all the newbs seem to have problems for some reason with cos and sin. I feel it is my responsibility then to provide help and give a quick description. I know this has been covered UBER amounts of time (Maybe this'll get stickied even)

First off, Sin is the opposite angle divided by the hypotenuse. Cos is the adjacent angle divided by the hypotenuse. Perhaps Kai will be kind enough to post his chart up again ;) Using sine (sin) is generally applied to the x value. Using cosine(cos) is generally applied to the y value. When moving around persay a light or something, this is the format you would use:
NPC Code:

if (action)
{ x=x+sin(angle)*distance;
y=y+cos(angle)*distance;
}


The x value gets added to the sin of the angle, then multiplied by the distance from the centre point. It isn't all that hard. Play with it a bit. Use a variable for angle and distance. Try and get things to move on a timeout or whatnot. It'll come in handy. I hope you find use for it and I explained what you did not understand. If you have any other questions, that haven't been answered in EVERY other cos/sin thread, ask away.
---Shifter

it would be more accurate to say

x=x+sin(angle)*radius;
y=y+cos(angle)*radius;

Dach 10-08-2002 06:41 PM

Re: Newb Gift: Circular Movement
 
Quote:

Originally posted by emortylone

First off, Sin is the opposite side divided by the hypotenuse. Cos is the adjacent side divided by the hypotenuse.


emortylone 10-08-2002 11:19 PM

It all deals with triangles, it isn't that hard to comprehend I think. Get in a GeoMetry class, perhaps even a lower Algebra class would be useful. If you need some equations, I can help you guys out. It just takes a bit getting used to. ANd yes, Distance is radius, but since the people seem to need help in this area, I assumed that using more mathmatical terms was unnecessary. I said it was the distance from the centre, basically the radius :D
---Shifter

R0bin 10-08-2002 11:31 PM

Even though the radius is diameter/2

Com013 10-09-2002 02:03 AM

Re: Newb Gift: Circular Movement
 
Quote:

Originally posted by emortylone
Using sine (sin) is generally applied to the x value. Using cosine(cos) is generally applied to the y value
No! The other way 'round! Normally a mathematical cricle starts right and continues counter-clockwise. In graal it'd be:
xvalue = cos(angle)
yvalue = -sin(angle)
"getangle" is doing the same, so to be compatible, just follow this.

R0bin 10-09-2002 06:24 AM

Thats because you were treating him like a 20 year old adult, and not like a little baby ;)


EDIT!!!

Shifter!!! WHAT ABOUT RADIANS??

Radian = Degree / 180 *3.142

So....

To show something at 45 degrees... to a point you would use
this.angle = 45/180*3.14;
x=x+sin(this.angle)*this.radius;
y=y+cos(this.angle)*this.radius;

emortylone 10-09-2002 06:27 AM

LOL, ain't THAT the truth Kai :P It was the best way to learn, but I know it can be aggravating. Knowing THAT something works doesn't mean you understand the command. Knowing WHY something works is when you can say you comprehend it.
---Shifter

Graal2001_NAT 10-09-2002 06:28 AM

...and who told you how to to that r0bin :P

emortylone 10-09-2002 06:29 AM

Same place he learns MOST of his new tricks ;) From meh :P and j00 :D
---Shifter ;)

R0bin 10-09-2002 06:29 AM

JAGEN! TEH 1337EST DUDE!!!!!!!!!!!!

(Yeah people were wondering... "where did r0bin get this extensive knowledge all of a sudden?")

NOT FROM YOU SHIFTER!!!

Jagen taught me everything i know <3

emortylone 10-09-2002 06:31 AM

WTF are you talking about bish?! WHO IM'ed ME asking to be taught cos and sin?!
---Shifter

R0bin 10-09-2002 06:32 AM

I did, but you taught me **** all :P

Bah i must have listened to jagen and not you :P

emortylone 10-09-2002 06:37 AM

I dunno, I'm feeling discredited and unloved here =/ You know I'd always help you... :(
---Shifter

R0bin 10-09-2002 06:41 AM

I still <3 you!! even if you dont come on aim any more :'(


All times are GMT +2. The time now is 07:29 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.