View Single Post
  #2  
Old 10-08-2002, 02:14 PM
R0bin R0bin is offline
Banned
R0bin's Avatar
Join Date: Oct 2002
Location: Wales, UK
Posts: 828
R0bin is on a distinguished road
Send a message via AIM to R0bin
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;
Reply With Quote