Discuss Scratch
- Discussion Forums
 - » Help with Scripts
 - » How do you make a sprite move with clicks?
        
         
- MaggotMush
 - 
                            
						
						
                            Scratcher
                        
						
						 
4 posts
How do you make a sprite move with clicks?
I've kind of been thinking of making a game in which you move by clicking on the place that you want to go. But I have no clue how to do this. We have the “go to mouse-pointer” script, but that's all I can think of that could help me with this. I know moving with the arrow keys would be a lot easier to script, but I want to test click movement, does anyone know if this is possible, and how? 
                        
                        
                    - MaggotMush
 - 
                            
						
						
                            Scratcher
                        
						
						 
4 posts
How do you make a sprite move with clicks?
I figured something out!
By making a whole new sprite for the background, you can add a message that tells the “player” where to move.
edit : Now the only problem left is figuring out how to set a walking animation when in movement. I'll try troubleshooting, but if anyone has any solutions please hit me up.
                        
                            By making a whole new sprite for the background, you can add a message that tells the “player” where to move.
when this sprite clicked
broadcast [message1]
when I receive [message1]
glide (1) secs to x: (mouse x) y: (mouse y)
edit : Now the only problem left is figuring out how to set a walking animation when in movement. I'll try troubleshooting, but if anyone has any solutions please hit me up.
Last edited by MaggotMush (Oct. 30, 2018 14:43:24)
- deck26
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ posts
How do you make a sprite move with clicks?
There is a ‘when stage clicked’ hat block as well.
                        
                        
                    - MaggotMush
 - 
                            
						
						
                            Scratcher
                        
						
						 
4 posts
How do you make a sprite move with clicks?
There is a ‘when stage clicked’ hat block as well.Oh yeah! I forgot about that, thank you.
- Stalpinth
 - 
                            
						
						
                            Scratcher
                        
						
						 
47 posts
How do you make a sprite move with clicks?
Here is a solution: https://scratch.mit.edu/projects/258536679/
                        
                        
                    - TheRandomno
 - 
                            
						
						
                            Scratcher
                        
						
						 
50 posts
How do you make a sprite move with clicks?
I made a project that moves at a roughly consistent speed and includes basic animation. If you had a sprite designed in overhead view you could change the rotation style to all-around.
It uses the workaround for the glide block which allows you to change costume every frame.
                        
                        
                    It uses the workaround for the glide block which allows you to change costume every frame.
- iFluxx
 - 
                            
						
						
                            Scratcher
                        
						
						 
100+ posts
How do you make a sprite move with clicks?
If you want the sprite to always move when you click, regardless where you click, do
                        
                        
                    when flag clickedOr you could use broadcasts
forever
if <mouse down?> then
change x by:()
change y by:()
end
end
When Flag Clicked
forever
if <mouse down?> then
broadcast [move v]
end
end
When I receive [move v]
change x by:()
change y by:()
- deck26
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ posts
How do you make a sprite move with clicks?
Mouse down isn't enough - holding the mouse down is not the same as clicking but the forever loop would only check the mouse down.  If you want to use @iFluxx's method you're better waiting until mouse down and waiting until not mouse down in the forever loop instead of having the if block.
The second method (broadcast) is one to be careful of. If the receiver gets any longer it may not complete between one broadcast and the next when it will restart.
                        
                        
                    The second method (broadcast) is one to be careful of. If the receiver gets any longer it may not complete between one broadcast and the next when it will restart.
- iFluxx
 - 
                            
						
						
                            Scratcher
                        
						
						 
100+ posts
How do you make a sprite move with clicks?
Mouse down isn't enough - holding the mouse down is not the same as clicking but the forever loop would only check the mouse down. If you want to use @iFluxx's method you're better waiting until mouse down and waiting until not mouse down in the forever loop instead of having the if block.Oh yeah forgot that lol
The second method (broadcast) is one to be careful of. If the receiver gets any longer it may not complete between one broadcast and the next when it will restart.
wait until <not <mouse down?>
Last edited by iFluxx (Nov. 1, 2018 18:21:12)
- 3DGamer5
 - 
                            
						
						
                            Scratcher
                        
						
						 
69 posts
How do you make a sprite move with clicks?
here is my way, make 2 sprites (one is for the player, one is for the cursor)
Sprite 2:
sprite 1:
and thats it.
BTW here is a template: https://scratch.mit.edu/projects/254200103
                        
                            Sprite 2:
when green flag clicked
broadcast [mouse v]
when I receive [mouse v]
repeat until <mouse down?>
go to [mouse pointer v]
end
broadcast [walk v]
sprite 1:
when I receive [walk v]
repeat until <touching [sprite2 v] ?>
point towards [sprite2 v]
move (10) steps
end
broadcast [mouse v]
and thats it.
BTW here is a template: https://scratch.mit.edu/projects/254200103
Last edited by 3DGamer5 (Nov. 1, 2018 20:38:56)
- Puppy_4_Life
 - 
                            
						
						
                            New Scratcher
                        
						
						 
1 post
How do you make a sprite move with clicks?
How do you make the background bigger. Meaning like in the minecraft 11v.3 by griffpatch made it possible for you to move around in the background and not have to touch something to change the background to another one. How do you do that?
                        
                        
                    - PersRufaro
 - 
                            
						
						
                            Scratcher
                        
						
						 
100+ posts
How do you make a sprite move with clicks?
How do you make the background bigger. Meaning like in the minecraft 11v.3 by griffpatch made it possible for you to move around in the background and not have to touch something to change the background to another one. How do you do that?Please don't post on old topics, but rather start your own. Try to remember next time.
- People might not respond to your question.
Last edited by PersRufaro (Feb. 16, 2020 05:46:30)
- cs4865242
 - 
                            
						
						
                            New Scratcher
                        
						
						 
1 post
How do you make a sprite move with clicks?
YOURE GETTING HACJED'
]
                        
                            ]
Last edited by cs4865242 (Feb. 24, 2020 15:49:23)
- Teku_841
 - 
                            
						
						
                            Scratcher
                        
						
						 
8 posts
How do you make a sprite move with clicks?
i mean this isnt about when you click and it moves there just reguler moving
                        
                        
                    when green flag clicked
set rotation style [ left right]
forever
if <key [ a] pressed?> then
point in direction ( -90)
move (10) steps
if <key [ d] pressed?> then
point in direction ( 90)
move (10) steps
end
end
end
- Teku_841
 - 
                            
						
						
                            Scratcher
                        
						
						 
8 posts
How do you make a sprite move with clicks?
sorry its
                        
                        
                    when green flag clicked
set rotation style [Left right ]
forever
if <key [a] pressed?> then
point in direction (-90)
move (10) steps
if <key [d] pressed?> then
point in direction (90)
move (10) steps
end
end
end
- Teku_841
 - 
                            
						
						
                            Scratcher
                        
						
						 
8 posts
How do you make a sprite move with clicks?
oh my god ok the if inside of the key a its supposed to go under the other if
                        
                        
                    
- Discussion Forums
 - » Help with Scripts
 - 
            » How do you make a sprite move with clicks? 
         








