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

#1 2013-04-17 13:03:10

mrdance62
New Scratcher
Registered: 2013-04-15
Posts: 13

How to make sprite follow another Sprite

Hi,
Some of you may know that I am making a basketball game. I am trying to make the cpu player go for the basketball. I tried doing this.

[scratchblocks]
when gf clicked
forever
      point in direction <sprite 1>
      move <10> steps
end

The problem is that it starts to go in the air and keeps spinning around. What should I do to program the cpu player to follow the ball while staying on the ground?

Offline

 

#2 2013-04-17 13:26:50

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to make sprite follow another Sprite

Hmmm.... Well, for one, i am assuming that this game is a side-view game? Meaning you are looking at the side of the players, not the top? If so, then you need to go to the left of the name of your cpu and click the "<->" button, this will keep it from spinning.
Next, i need to know something, can the cpu jump? Other than throwing the ball? If not, then just say this:

when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] > >
if < ([x position v] of [ball v]) < (x position)>
change x by [-3]
else
change x by [3]

This is of course, without any velocity, but that should work as long as the cpu is always at the same y position. Also, you can add any other conditional variables that you want, but the ones i added are the ones you will probably need.  wink

Regards,

CAA14

Last edited by CAA14 (2013-04-17 13:42:22)

Offline

 

#3 2013-04-17 13:35:05

topazdragonlord
Scratcher
Registered: 2013-02-22
Posts: 500+

Re: How to make sprite follow another Sprite

CAA14 wrote:

Hmmm.... Well, for one, i am assuming that this game is a side-view game? Meaning you are looking at the side of the players, not the top? If so, then you need to go to the left of the name of your cpu and click the "<->" button, this will keep it from spinning.
Next, i need to know something, can the cpu jump? Other than throwing the ball? If not, then just say this:

when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] >
if <([x position v] of [ball v]) > (x position)>
change x by [-3]
else
change x by [3]

This is of course, without any velocity, but that should work as long as the cpu is always at the same y position. Also, you can add any other conditional variables that you want, but the ones i added are the ones you will probably need.  wink

Regards,

CAA14

when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] >>
if <([x position v] of [ball v]) > (x position) >
change x by [-3]
else
change x by [3]

Fixed the scratch-blocks for you  smile
-topazdragonlord

Last edited by topazdragonlord (2013-04-17 13:40:09)


http://i45.tinypic.com/idumbk.png

Offline

 

#4 2013-04-17 13:37:17

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to make sprite follow another Sprite

topazdragonlord wrote:

CAA14 wrote:

Hmmm.... Well, for one, i am assuming that this game is a side-view game? Meaning you are looking at the side of the players, not the top? If so, then you need to go to the left of the name of your cpu and click the "<->" button, this will keep it from spinning.
Next, i need to know something, can the cpu jump? Other than throwing the ball? If not, then just say this:

when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] >
if < [x position v] of [ball v] > (x position) >
change x by [-3]
else
change x by [3]

This is of course, without any velocity, but that should work as long as the cpu is always at the same y position. Also, you can add any other conditional variables that you want, but the ones i added are the ones you will probably need.  wink

Regards,

CAA14

when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] >>
if < [x position v] of [ball v] > (x position) >
change x by [-3]
else
change x by [3]

Fixed the scratch-blocks for you  smile
-topazdragonlord

Thanks, but i was editing it, check it now.  smile
Well, it doesn't like "<"...

Regards,

CAA14

Last edited by CAA14 (2013-04-17 13:40:22)

Offline

 

#5 2013-04-17 13:41:01

topazdragonlord
Scratcher
Registered: 2013-02-22
Posts: 500+

Re: How to make sprite follow another Sprite

CAA14 wrote:

topazdragonlord wrote:

CAA14 wrote:

Hmmm.... Well, for one, i am assuming that this game is a side-view game? Meaning you are looking at the side of the players, not the top? If so, then you need to go to the left of the name of your cpu and click the "<->" button, this will keep it from spinning.
Next, i need to know something, can the cpu jump? Other than throwing the ball? If not, then just say this:

when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] >
if < [x position v] of [ball v] > (x position) >
change x by [-3]
else
change x by [3]

This is of course, without any velocity, but that should work as long as the cpu is always at the same y position. Also, you can add any other conditional variables that you want, but the ones i added are the ones you will probably need.  wink

Regards,

CAA14

when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] >>
if < [x position v] of [ball v] > (x position) >
change x by [-3]
else
change x by [3]

Fixed the scratch-blocks for you  smile
-topazdragonlord

Thanks, but i was editing it, check it now.  smile
Well, it doesn't like "<"...

Regards,

CAA14

lol  big_smile  - btw IU fixed the "<"  smile
-topazdragonlord


http://i45.tinypic.com/idumbk.png

Offline

 

#6 2013-04-17 13:41:48

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to make sprite follow another Sprite

topazdragonlord wrote:

CAA14 wrote:

topazdragonlord wrote:


when i receive [gameStart v]
repeat until < < (gameOver?) = [yes] > or < (holdingBall?) = [yes] >>
if < [x position v] of [ball v] > (x position) >
change x by [-3]
else
change x by [3]

Fixed the scratch-blocks for you  smile
-topazdragonlord

Thanks, but i was editing it, check it now.  smile
Well, it doesn't like "<"...

Regards,

CAA14

lol  big_smile  - btw I fixed the "<"  smile
-topazdragonlord

Thanks, man that is annoying when it does that.  smile

Regards,

CAA14

Offline

 

#7 2013-04-17 13:45:31

topazdragonlord
Scratcher
Registered: 2013-02-22
Posts: 500+

Re: How to make sprite follow another Sprite

CAA14 wrote:

topazdragonlord wrote:

CAA14 wrote:


Thanks, but i was editing it, check it now.  smile
Well, it doesn't like "<"...

Regards,

CAA14

lol  big_smile  - btw I fixed the "<"  smile
-topazdragonlord

Thanks, man that is annoying when it does that.  smile

Regards,

CAA14

Your welcome  smile
-topazdragonlord


http://i45.tinypic.com/idumbk.png

Offline

 

#8 2013-04-17 19:02:45

mrdance62
New Scratcher
Registered: 2013-04-15
Posts: 13

Re: How to make sprite follow another Sprite

The cpu cannot throw the ball or jump, unfortunately.

Offline

 

#9 2013-04-17 19:05:16

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: How to make sprite follow another Sprite

mrdance62 wrote:

The cpu cannot throw the ball or jump, unfortunately.

Okay, then that should work.  smile

Regards,

CAA14

Offline

 

Board footer