This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-02-19 12:44:42

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

How to make a sprite go to the end of another sprite?

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

Code:

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.


Alt of Firedrake969.

Offline

 

#2 2013-02-19 14:50:06

piguillaud
Scratcher
Registered: 2010-06-19
Posts: 100+

Re: How to make a sprite go to the end of another sprite?

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

 

#3 2013-02-19 14:59:43

Nomolos
Scratcher
Registered: 2011-07-29
Posts: 1000+

Re: How to make a sprite go to the end of another sprite?

piguillaud wrote:

Im not great at explaining, but i made an example, just take the code:
Here

FIxed the link


Goodbye 1.4. I'll always remember you and treasure your awesomeness in my heart.
RIP 1.4: 2007-2013 *Sniffles* *Sobs* *Bursts into tears*

Offline

 

#4 2013-02-19 15:02:23

piguillaud
Scratcher
Registered: 2010-06-19
Posts: 100+

Re: How to make a sprite go to the end of another sprite?

That works i guess  smile

Offline

 

#5 2013-02-19 19:22:08

bob6
Scratcher
Registered: 2010-07-01
Posts: 100+

Re: How to make a sprite go to the end of another sprite?

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.


http://i46.tinypic.com/3148ksz.gif

Offline

 

#6 2013-02-19 19:37:29

piguillaud
Scratcher
Registered: 2010-06-19
Posts: 100+

Re: How to make a sprite go to the end of another sprite?

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

 

#7 2013-02-19 20:20:46

bob6
Scratcher
Registered: 2010-07-01
Posts: 100+

Re: How to make a sprite go to the end of another sprite?

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.


http://i46.tinypic.com/3148ksz.gif

Offline

 

#8 2013-02-20 09:31:18

firedrake969_test
Scratcher
Registered: 2012-08-08
Posts: 500+

Re: How to make a sprite go to the end of another sprite?

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)


Alt of Firedrake969.

Offline

 

#9 2013-02-20 12:38:06

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: How to make a sprite go to the end of another sprite?

Closed by request of the topic owner.

Congratulations on your triumph  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer