Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how to make a sprite push another sprite
- firepawz_
-
Scratcher
6 posts
how to make a sprite push another sprite
im working on a scratch remake of the king fight for deltarune and there is one attack where he moves a box that the player is suppost to stay inside but when it moves the player just goes right through the box anyone know a way to keep the player inside it?
Last edited by firepawz_ (Nov. 28, 2018 13:51:53)
- RokCoder
-
Scratcher
1000+ posts
how to make a sprite push another sprite
Can you share your project so people can see the problem and are then able to suggest ways to fix it for you?
- firepawz_
-
Scratcher
6 posts
how to make a sprite push another sprite
https://scratch.mit.edu/projects/265235853/ on the second attack for the king boss fight the box that the player is suppost to stay in moves around but i dont know how to make it so that it pushes the soul/heart
Last edited by firepawz_ (Nov. 28, 2018 14:40:10)
- JEMA2311
-
Scratcher
65 posts
how to make a sprite push another sprite
Hi firepawz, this the solution I could come up with:
Note: all of this has to be done in your heart sprite
1- Create this local variables.
2- Add this script:
3- Modify the script that makes the heart to move like this:
Another note: By doing this, it´s possible that your heart sprite might look like is being dragged by the black box (which is actually true, the heart is trying to keep up with the box coordinates). If that doesn't bother you, then you are good to go, otherwise you will have to create a new object , so the black box AND the heart can follow this new object, and since both are being dragged, boom, problem solved!
Let us know if you need more help!
Note: all of this has to be done in your heart sprite
1- Create this local variables.
(xpos)
(ypos)
2- Add this script:
when I receive [enemy turn v]
set [ypos v] to [0]
set [xpos v] to [0]
repeat until <not <[(turn)] = [enemy]>>
go to x: ((xpos) + ([x position v] of [Sprite5 v])) y: ((ypos) + ([y position v] of [Sprite5 v]))
end
3- Modify the script that makes the heart to move like this:
if <key [up arrow v] pressed?> then
change [ypos v] by (5)
if <(ypos) > [10]> then
set [ypos v] to [10]
end
end
if <key [down arrow v] pressed?> then
change [ypos v] by (-5)
if <(ypos) < [-30]> then
set [ypos v] to [-30]
end
end
if <key [left arrow v] pressed?> then
change [xpos v] by (-5)
if <(xpos) < [-55]> then
set [xpos v] to [-55]
end
end
if <key [right arrow v] pressed?> then
change [xpos v] by (5)
if <(xpos) > [45]> then
set [xpos v] to [45]
end
end
Another note: By doing this, it´s possible that your heart sprite might look like is being dragged by the black box (which is actually true, the heart is trying to keep up with the box coordinates). If that doesn't bother you, then you are good to go, otherwise you will have to create a new object , so the black box AND the heart can follow this new object, and since both are being dragged, boom, problem solved!
Let us know if you need more help!

Last edited by JEMA2311 (Nov. 28, 2018 16:42:02)
- Sqperdoo
-
Scratcher
100+ posts
how to make a sprite push another sprite
Hi firepawz, this the solutionNo, no, no, no, there is a finest solution that you could make in two scripts:
Let us know if you need more help!
· In the pushing sprite you do
when green flag clicked· In the pushed sprite you do
forever
set rotation style [don't rotate v]
if <touching [Pushed v] ?> then
point towards [Pushed v]
set [Direction v] to (direction)
broadcast [Push v]
end
end
when I receive [Push v]If you want you can change the block "Set rotation style" to whatever you want
point in direction (Direction)
set rotation style [don't rotate v]
move (10) steps
if on edge, bounce
Last edited by Sqperdoo (Nov. 28, 2018 17:11:18)
- firepawz_
-
Scratcher
6 posts
how to make a sprite push another sprite
Sqperdoo sorry but, this script seems to be trying to keep the char outside the box, the char is suppost to stay inside the box, not outside
- JEMA2311
-
Scratcher
65 posts
how to make a sprite push another sprite
Sqperdoo sorry but, this script seems to be trying to keep the char outside the box, the char is suppost to stay inside the box, not outsideYou have to keep in mind that the title you wrote says “how to PUSH a sprite”, but at the end you don't need anything to be pushed (if I understood correctly)
Sqperdoo is giving you the solution the title is asking for (push a sprite with another sprite).
Please give it a try with the solution I suggested, hopefully it is what you need. If it is not, let me/us know, so we can try something different
- deck26
-
Scratcher
1000+ posts
how to make a sprite push another sprite
For the box your best bet might be to use the distance to block. If the player moves and the centre of the box goes above a certain distance from the player the box needs to move as well.
Then use the scripts above to move the object that the block pushes. Do this via broadcasts rather than forever loops so the scripts stay in sync.
Then use the scripts above to move the object that the block pushes. Do this via broadcasts rather than forever loops so the scripts stay in sync.
- firepawz_
-
Scratcher
6 posts
how to make a sprite push another sprite
i accually managed to find a solution (im fairly knew to scratch so i dont know how to close a discussion)
Last edited by firepawz_ (Nov. 30, 2018 12:37:00)
- deck26
-
Scratcher
1000+ posts
how to make a sprite push another sprite
i accually managed to find a solution (im fairly knew to scratch so i dont know how to close a discussion)There should be an option for you, as the owner, to close a topic after 24 hours. I think it appears at the bottom of the topic thread.
- Jimbob4444
-
Scratcher
1 post
how to make a sprite push another sprite
Yes but how can you use an or block for to sprites
- game_pr0grammer
-
Scratcher
500+ posts
how to make a sprite push another sprite
Yes but how can you use an or block for to sprites
Despite the small chance that you will see this message, you have just necroposted. I know you are new to forums in general, so it is not your fault you don't know that what you just did is a criminal offense. If you reply to a topic, it gets pushed to the top of the forums. But this is a really old topic so nobody cares about this and people find this annoying.
tl;dr no replying to old topics it's bad
- OOOFREE9050
-
Scratcher
12 posts
how to make a sprite push another sprite
im trying to make this doggo undertale battle but i definitley agree with the pictures
i just wanna put some code here
to move up:
i just wanna put some code here
to move up:
when green flag clicked
if <> then
<key [^] pressed?>
change y by (3)
- OOOFREE9050
-
Scratcher
12 posts
how to make a sprite push another sprite
my bad
when green flag clicked
if <key [^] pressed?> then
change y by (3)
end
- potatohead_1011
-
Scratcher
100+ posts
how to make a sprite push another sprite
im trying to make this doggo undertale battle but i definitley agree with the pictures
i just wanna put some code here
to move up:when green flag clickedif <> then
<key [^] pressed?>
change y by (3)[/quote]
Whyyyyyyyyyyyyyyyyyyyyyyyyy
- Discussion Forums
- » Help with Scripts
-
» how to make a sprite push another sprite