Hi, I want a suggestion for my project.
I’ve a ball that can move automatically on 8 directions (N,NE,E,SE,S,SW,W,NW).
I’ve to build an array with this directions??
Hi, I want a suggestion for my project.
I’ve a ball that can move automatically on 8 directions (N,NE,E,SE,S,SW,W,NW).
I’ve to build an array with this directions??
Well u might make an array with sin and cos values for given angles. Then do the math for coordinates.
So, an array where on the first element I put (0) on the second (PI/4) on the third (PI/2) …or what??
In an array you put the radians of the different directions like this:
North = Pi/2
East = 0
West = Pi
(you complete the rest)
then by doing:
xPos += Math.cos(array[direction]);
yPos += Math.sin(array[direction]);
you are moving the ball in the direction you want, and can change the direction if you please. by changing the variable direction.
salutes
Or to save the sin/cos time, you make a 2 dimensional array with the +x and +y once using sin/cos.
After that you just add the apppropriate one to the ball’s x and y for each move.
But i gotta say, this smells of homework. Any time someone says "I have to use but it is clear they have no idea what to do with it, it stinks of an assignment…