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

#1 2013-04-15 20:38:34

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

How to make sprite hold another sprite.

Hi,
I am working on making a basketball game in scratch. I want to make it so that one sprite can pick up the basketball when it is rolling around. I also want to make it so that if the basketball is touching the top of the net, it will slide through. Would anyone be able to help me with that?

Offline

 

#2 2013-04-15 21:04:20

mikebmac
Scratcher
Registered: 2013-03-17
Posts: 46

Re: How to make sprite hold another sprite.

You would set it's (the ball's) x and y axis based off the holders position with an offset.

when gf clicked
forever
  if <(player_holding_ball)= (1)>
    go to x: <<(x position v) of (player v)> + (25)> y: <<(y position v) of (player v)> - (25)>
So you can setup some script for setting when sprite 1 has the ball you set the variable "player_holding_ball" to 1, then the script above will run.

The +25 of the x axis and -25 of the y axis are the amount of offset you want the ball to follow the sprite around at.


http://i42.tinypic.com/21lo482.jpg HD Crash will restart production after 2.0
Related: (Concept Game) (Heroine Bio) (Sample Scroller /w Heroine Animation)

Offline

 

#3 2013-04-16 08:25:57

crushed377
New Scratcher
Registered: 2013-04-16
Posts: 9

Re: How to make sprite hold another sprite.

Write it so its in forever if, then touching player, then go to player.

Offline

 

#4 2013-04-16 11:46:49

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

Re: How to make sprite hold another sprite.

crushed377 wrote:

Write it so its in forever if, then touching player, then go to player.

forever if <touching? [Player v]>
go to [player v]
Actually, is you're using what the first responder said, you should just have this:

when gf clicked
forever
if < (holding?) = [yes] >
go to x: < [x position v] of [player v] > y: < [y position v] of [player v] >
You of course add an offset like the first responder showed, and then:

when gf clicked
forever
if <touching? [player v] >
set [holding? v] to [yes]
else
set [holding? v] to [no]
Regards,

CAA14

Offline

 

#5 2013-04-17 11:29:14

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

Re: How to make sprite hold another sprite.

Thanks, but I'm having a problem. When I jump, I let go of the ball. How can I program it to stay in the players hands when I jump.

Offline

 

#6 2013-04-17 12:38:37

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

Re: How to make sprite hold another sprite.

mrdance62 wrote:

Thanks, but I'm having a problem. When I jump, I let go of the ball. How can I program it to stay in the players hands when I jump.

Hmm... using the above scripts should keep it there regardless, could you post your scripts or at least the scripts that pertain to the holding and jumping?

And, no problem.  smile

Regards,

CAA14

Offline

 

#7 2013-04-17 19:09:39

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

Re: How to make sprite hold another sprite.

This is my script for holding:

[scratchblocks]
when gf clicked
forever
    if touching <player>
          go to x: x position of sprite + 25 y: y position of sprite
end

My script for making me jump is:

When up arrow key pressed
Change y by 100

Offline

 

#8 2013-04-17 19:15:35

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

Re: How to make sprite hold another sprite.

mrdance62 wrote:

This is my script for holding:

when gf clicked
forever
    if touching <player>
          go to x: x position of sprite + 25 y: y position of sprite 
end
My script for making me jump is:

When up arrow key pressed
Change y by 100

Okay, try putting another forever loop in it, like this:

when gf clicked
forever 
if < touching? [player v] >
forever
go to x: <[x position v] of [player v]> y: (<[y position v] of [player v]> + [25])
end
end
end

Also, You need to have your jumping script go down 100 after a certain amount of time. Are you doing this?

Regards,

CAA14

P.S. You just needed a "/" before the last "scratchblocks".  wink

Last edited by CAA14 (2013-04-17 19:17:39)

Offline

 

#9 2013-04-20 10:04:46

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

Re: How to make sprite hold another sprite.

I tried that script, when I jump its okay. However, when I try to shoot the ball, it just comes right back at me. I will try to do something like this:

[/scratchblocks]
when gf clicked
forever
     if (touching <ball>)
         forever if (touching <ball>)
             go to x position of ball + 25 y position of ball

Offline

 

#10 2013-04-20 10:16:07

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

Re: How to make sprite hold another sprite.

mrdance62 wrote:

I tried that script, when I jump its okay. However, when I try to shoot the ball, it just comes right back at me. I will try to do something like this:

[/scratchblocks]
when gf clicked
forever
     if (touching <ball>)
         forever if (touching <ball>)
             go to x position of ball + 25 y position of ball

Actually, that didn't work. Maybe I can try something like this for the ball script:

when gf clicked
forever
      wait until (touching <player 1>) 
      if (touching <player 1>)
           forever 
               go to (<x position> of <player 1> <y position> of <player 1>  
      end 

Offline

 

#11 2013-04-20 11:01:12

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: How to make sprite hold another sprite.

mrdance62 wrote:

mrdance62 wrote:

I tried that script, when I jump its okay. However, when I try to shoot the ball, it just comes right back at me. I will try to do something like this:

[/scratchblocks]
when gf clicked
forever
     if (touching <ball>)
         forever if (touching <ball>)
             go to x position of ball + 25 y position of ball

Actually, that didn't work. Maybe I can try something like this for the ball script:

when gf clicked
forever
      wait until <touching [player1 v] ?>
      if <touching [player 1 v]?>
           forever 
               go to x: ([x position v] of [player 1 v]) y: ([y position v] of [player 1 v])
      end 

Fixed  big_smile

With regards
~7734f


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#12 2013-04-20 19:03:01

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

Re: How to make sprite hold another sprite.

Ugh, nothing is working! I'll keep trying. If any of you have any possible scripts that could work, please respond.

Offline

 

#13 2013-04-20 19:42:41

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

Re: How to make sprite hold another sprite.

Ok, I did this script for the ball:

when gf clicked
forever
     if (touching <player 1>)
     repeat until (key <space> pressed) or (touching <player 2>
     go to x position of player 1 + 25 and y position of player 1 
     end 
end
One problem, MY GRAVITY IS NOT WORKING! This is just problem after problem after problem. Here is my script for gravity:

when gf clicked
if <not (touching color <ground>)>
    change y by [-4]  
    end
end 
[/scratchhblocks]

Offline

 

#14 2013-04-20 21:46:24

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

Re: How to make sprite hold another sprite.

mrdance62 wrote:

Ok, I did this script for the ball:

when gf clicked
forever
     if (touching <player 1>)
     repeat until (key <space> pressed) or (touching <player 2>
     go to x position of player 1 + 25 and y position of player 1 
     end 
end
One problem, MY GRAVITY IS NOT WORKING! This is just problem after problem after problem. Here is my script for gravity:

when gf clicked
forever
if <not<touching? [ground v]>>
    change y by [-4]  
    end
end 

What is wrong with the gravity? My guess is that its going below that ground, right?

Also, about your script for the ball, It should work fine, what's happening wrong?

Regards,

CAA14

Last edited by CAA14 (2013-04-20 21:47:52)

Offline

 

#15 2013-04-20 22:59:06

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

Re: How to make sprite hold another sprite.

Actually, I have resolved all of the problems. Thank you all, including CAA14, and everyone for helping me out. I am thankful for experienced scratchers who are willing to pass their knowledge down to one who is a rookie. I will upload my game shortly, and it will go out to all of you. Thank you again.

Offline

 

#16 2013-04-20 23:35:20

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

Re: How to make sprite hold another sprite.

mrdance62 wrote:

Actually, I have resolved all of the problems. Thank you all, including CAA14, and everyone for helping me out. I am thankful for experienced scratchers who are willing to pass their knowledge down to one who is a rookie. I will upload my game shortly, and it will go out to all of you. Thank you again.

That's great, and no problem. Actually, i just started in January of this year, so i am just steadily learning.  smile 

Looking forward to playing your game.  wink

Regards,


CAA14

Offline

 

#17 2013-04-21 14:26:51

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

Re: How to make sprite hold another sprite.

CAA14 wrote:

mrdance62 wrote:

Actually, I have resolved all of the problems. Thank you all, including CAA14, and everyone for helping me out. I am thankful for experienced scratchers who are willing to pass their knowledge down to one who is a rookie. I will upload my game shortly, and it will go out to all of you. Thank you again.

That's great, and no problem. Actually, i just started in January of this year, so i am just steadily learning.  smile 

Looking forward to playing your game.  wink

Regards,


CAA14

Should be up in a few days, CAA14. just have to make the finishing touches!  smile

Offline

 

Board footer