Pages: 1
Topic closed
I have a sprite, somewhat like a bar, that has its center on one side of it. Another bar has to have one side of IT go to the opposite side of the other sprite. However, I can't figure out how to do this. The script for the first sprite is
forever if up arrow pressed turn ccw 2 degrees if down arrow pressed turn cw 2 degrees
Trig is welcome, but please explain what it does.
Offline
Im not great at explaining, but i made an example, just take the code:
Click me!
Last edited by piguillaud (2013-02-19 15:03:11)
Offline
piguillaud wrote:
Im not great at explaining, but i made an example, just take the code:
Here
FIxed the link
Offline
That works i guess
Offline
Well, here is how I would do it.
I am assuming that you mean that you want another bar to spin freely at the end of the first bar.
1. Set the first bar's center to the end (no duh)
a. I am assuming that the fulcrum of this bar is on point (0, 0)
b. Make a constant to hold the bar's length. (Let's call this "length")
2. set the second bar's center to the end (no duh)
3. Now we need a code to find where the opposite side of the first bar is located.
a. First, make a variable to record the direction the bar is pointing (right means 0, up means 90, etc.)
b. Now for the trig part. The point on the other side of the first bar has a x value of:
length * cos(direction)
The y value is:
length * sin(direction)
4. Now, continuously set the second bar to go to these coordinates.
Now you are done! Hope this helped.
Offline
bob, the problem is that in scratch the directions are not 360, but 0 90 180 -90 0. for that you have to create a variable making it keep the direction when the direction is between 0 and 180, and make it do ([360] - <abs of> [direction]), so that it goes to 360
Offline
piguillaud wrote:
bob, the problem is that in scratch the directions are not 360, but 0 90 180 -90 0. for that you have to create a variable making it keep the direction when the direction is between 0 and 180, and make it do ([360] - <abs of> [direction]), so that it goes to 360
Actually, using the (direction) block will actually let it be 0-360 (or 0-2pi if you want to say it formally), so that is not a problem. If you are talking about the "simple" direction block, then you are correct.
Offline
Can you guys write an explanation in addition?
Note to myself--compensate for the length of the arm - the part of the arm hidden offscreen, perharps? Or not.
EDIT: YESYESYES I USED TRIG FOR THE FIRST TIME FOR SOMETHING USEFUL! :DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
Closing.
Last edited by firedrake969_test (2013-02-20 12:20:40)
Offline
Closed by request of the topic owner.
Congratulations on your triumph
Offline
Topic closed
Pages: 1