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

#1 2008-08-04 14:23:30

lucie
Scratcher
Registered: 2008-08-04
Posts: 1

How to get a ball to follow the mouse

I am trying to make a basketball game. I am new to the software. I want to make the ball follow where the mouse goes when the user clicks on it, and then give them a point if they score a basket.

Offline

 

#2 2008-08-04 14:25:51

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: How to get a ball to follow the mouse

Well, I would use variables. Alrighty:

Make 2 variables. Name one of them {mouse X} and the other {mouse Y}

Now put this script in:

<when green flag clicked>
<forever>
<if><mouse down?>
<set{ Mouse X  }to( <mouse x>
<set{ Mouse Y  }to( <mouse y>
<glide(  )secs to x sad  <{ Mouse X  }> )y sad  <{ Mouse Y  }>
<end>
<end>

I use the variables in case you move your mouse


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#3 2008-08-04 15:16:08

Zelda123
Scratcher
Registered: 2007-11-21
Posts: 1000+

Re: How to get a ball to follow the mouse

Bluestribute wrote:

Well, I would use variables. Alrighty:

Make 2 variables. Name one of them {mouse X} and the other {mouse Y}

Now put this script in:

<when green flag clicked>
<forever>
<if><mouse down?>
<set{ Mouse X  }to( <mouse x>
<set{ Mouse Y  }to( <mouse y>
<glide(  )secs to x sad  <{ Mouse X  }> )y sad  <{ Mouse Y  }>
<end>
<end>

I use the variables in case you move your mouse

Couldn't you just put the Mouse X and Mouse Y in the Glide Secs script instead?

Offline

 

#4 2008-08-04 15:45:25

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: How to get a ball to follow the mouse

Zelda123 wrote:

Bluestribute wrote:

Well, I would use variables. Alrighty:

Make 2 variables. Name one of them {mouse X} and the other {mouse Y}

Now put this script in:

<when green flag clicked>
<forever>
<if><mouse down?>
<set{ Mouse X  }to( <mouse x>
<set{ Mouse Y  }to( <mouse y>
<glide(  )secs to x sad  <{ Mouse X  }> )y sad  <{ Mouse Y  }>
<end>
<end>

I use the variables in case you move your mouse

Couldn't you just put the Mouse X and Mouse Y in the Glide Secs script instead?

What if you move the mouse?


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#5 2008-08-04 20:11:43

SeanCanoodle
Scratcher
Registered: 2008-06-20
Posts: 100+

Re: How to get a ball to follow the mouse

I just tried it out, you don't need variables because moving the mouse doesn't change where the glide finishes. Just stick MouseX and MouseY there.

Offline

 

#6 2008-08-04 21:13:57

Zelda123
Scratcher
Registered: 2007-11-21
Posts: 1000+

Re: How to get a ball to follow the mouse

Bluestribute wrote:

Zelda123 wrote:

Bluestribute wrote:

Well, I would use variables. Alrighty:

Make 2 variables. Name one of them {mouse X} and the other {mouse Y}

Now put this script in:

<when green flag clicked>
<forever>
<if><mouse down?>
<set{ Mouse X  }to( <mouse x>
<set{ Mouse Y  }to( <mouse y>
<glide(  )secs to x sad  <{ Mouse X  }> )y sad  <{ Mouse Y  }>
<end>
<end>

I use the variables in case you move your mouse

Couldn't you just put the Mouse X and Mouse Y in the Glide Secs script instead?

What if you move the mouse?

Since it's forever setting the variables to Mouse X and Y, it doesn't make a difference.

Offline

 

Board footer