I have 2 sprites that I want to always be the same distance away from each other. I can make a sprite a certain distance away on the x-axis which is easy. But could anyone give me an idea of how to keep a sprite the same distance away taking into account the
x and y axis?
Offline
rep353 wrote:
I have 2 sprites that I want to always be the same distance away from each other. I can make a sprite a certain distance away on the x-axis which is easy. But could anyone give me an idea of how to keep a sprite the same distance away taking into account the
x and y axis?
[Forever]
[Go to [(Y position of sprite 2) - (distance away)]
[End forever]
Offline
Do you want the complex yet perfect script? Here:
Modify the "x/y position of sprite 1" to whatever sprite you're following and set the distance variable to how far you want them apart.
Last edited by Kileymeister (2011-02-02 19:20:14)
Offline
Or the insanely-simple-but-unfortunately-renders-your-direction-unusable script:
Or if you want the sprite behind instead of ahead, use this:
Last edited by Kileymeister (2011-02-02 19:26:54)
Offline
bbbeb wrote:
Kiley, can you teach me trigonometry?
![]()
I'm in the Seventh grade yet we are yet to learn it.
![]()
Sure, alright. Here's a crash course (keep in mind I'm no teacher, and learning it in class later will make this a lot clearer).
Trigonometry deals mostly with triangles (most commonly right triangles) and the angles and sides they have. Trigonometric functions such as sine and cosine are used to tell if two triangles are congruent, or in scratch, they are used mainly for scripts concerning direction, though have many uses.
For sine, you take an angle on a right triangle (not the right angle) and use it to find the length of the side opposite the angle divided by the hypotenuse (the side opposite the right angle and the longest side). Cosine (shortened to "cos") uses the side next to the angle (the side that isn't the hypotenuse) but otherwise is the same. These fraction can be used to figure out how much a sprite should move horizontally and vertically when moving according to its direction (move 10 steps can be recreated using sine and cosine, useful for scrolling). For example, "change x by (sine of direction * 5)" plus "change y by (cos of direction *5)" is the same as "move 5 steps.
Tangent is similar to sine and cos, but it doesn't use the hypotenuse. Instead of opposite/hypotenuse of adjacent/hypotenuse it uses opposite/adjecent.
Asine, Acos, and Atan are the direct reverse of sine, cosine and tangent. Instead of taking the angle to find the fraction of the sides, it takes the fraction of the sides to find the angle. The atan of an x position divided by the y position of a point on a graph can give you the direction to point towards that point on the graph if your sprite is at 0,0.
There's many uses for sine, cos, tan, asine, acos, and atan, and I only know a few, but if you play around with them, experimenting, you can come up with some uses of your own. Looking at people's projects using these functions is a good way to learn how you can apply them yourself, I learned a lot about using them from seeing others applying them themselves.
Yes, it's all a little confusing, and it'll make much more sense when you learn it in a classroom, but that's my basic overview of it.
Last edited by Kileymeister (2011-02-02 20:37:25)
Offline
Kileymeister wrote:
bbbeb wrote:
Kiley, can you teach me trigonometry?
![]()
I'm in the Seventh grade yet we are yet to learn it.
![]()
Sure, alright. Here's a crash course (keep in mind I'm no teacher, and learning it in class later will make this a lot clearer).
Trigonometry deals mostly with triangles (most commonly right triangles) and the angles and sides they have. Trigonometric functions such as sine and cosine are used to tell if two triangles are congruent, or in scratch, they are used mainly for scripts concerning direction, though have many uses.
For sine, you take an angle on a right triangle (not the right angle) and use it to find the length of the side opposite the angle divided by the hypotenuse (the side opposite the right angle and the longest side). Cosine (shortened to "cos") uses the side next to the angle (the side that isn't the hypotenuse) but otherwise is the same. These fraction can be used to figure out how much a sprite should move horizontally and vertically when moving according to its direction (move 10 steps can be recreated using sine and cosine, useful for scrolling). For example, "change x by (sine of direction * 5)" plus "change y by (cos of direction *5)" is the same as "move 5 steps.
Tangent is similar to sine and cos, but it doesn't use the hypotenuse. Instead of opposite/hypotenuse of adjacent/hypotenuse it uses opposite/adjecent.
Asine, Acos, and Atan are the direct reverse of sine, cosine and tangent. Instead of taking the angle to find the fraction of the sides, it takes the fraction of the sides to find the angle. The atan of an x position divided by the y position of a point on a graph can give you the direction to point towards that point on the graph if your sprite is at 0,0.
There's many uses for sine, cos, tan, asine, acos, and atan, and I only know a few, but if you play around with them, experimenting, you can come up with some uses of your own. Looking at people's projects using these functions is a good way to learn how you can apply them yourself, I learned a lot about using them from seeing others applying them themselves.
Yes, it's all a little confusing, and it'll make much more sense when you learn it in a classroom, but that's my basic overview of it.
Ah, I understand it. Thank you!
(Do you learn it in geometry or algebra 2?)
Offline
bbbeb wrote:
Ah, I understand it. Thank you!
(Do you learn it in geometry or algebra 2?)
I learned it in Geometry, I don't know about other schools.
Offline
Kileymeister wrote:
bbbeb wrote:
Ah, I understand it. Thank you!
(Do you learn it in geometry or algebra 2?)I learned it in Geometry, I don't know about other schools.
Then I probably will too. Algebra 2 was said to use a lot of that from the start.
Offline