Discuss Scratch
- Discussion Forums
 - » Help with Scripts
 - »  X and Y position help
        
         
- Fin_co
 - 
                            
						
						
                            Scratcher
                        
						
						 
17 posts
X and Y position help
Hi!
 I am making a point and shoot game and I need the bullet to go to where an actor following the mouse is. I was suggested to do this,
The problem is the cross hair moves a lot and I don't know how to get the position of the cross hair into the glide block!
 So if anyone could help with that it would be much appreciated.
                        
                        
                    
 I am making a point and shoot game and I need the bullet to go to where an actor following the mouse is. I was suggested to do this,when I receive [ Shootv]
show
go to [gun v]
glide () secs to x: (Corss hair X) y: (Cross hair Y)
The problem is the cross hair moves a lot and I don't know how to get the position of the cross hair into the glide block!
 So if anyone could help with that it would be much appreciated.
- mstone326
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ posts
X and Y position help
Can you share.
I would do something like this:
                        
                            I would do something like this:
when I receive [shoot]
go to [gun ]
point towards [mouse pointer v]
repeat until < <<touching [edge v] ?> or <touching [bad guy v] ?>>>
move (10) steps
end
hide
Last edited by mstone326 (Feb. 11, 2017 19:16:38)
- ThanksAnts_Thants
 - 
                            
						
						
                            Scratcher
                        
						
						 
63 posts
X and Y position help
To get the position of the crosshair, try using this in the crosshair sprite.
That'll record the position of the cross hair whenever you click to those two variables, allowing you to use them in the glide-to script.
                        
                            when green flag clicked
if <mouse down?> then
set [Cross X v] to (x position)
set [Cross Y v] to (Y position)
end
That'll record the position of the cross hair whenever you click to those two variables, allowing you to use them in the glide-to script.
Last edited by ThanksAnts_Thants (Feb. 11, 2017 20:26:25)
- deck26
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ posts
X and Y position help
No need for extra variables if the crosshair is a single sprite, the sensing block can access the x and y position.
                        
                        
                    ([x-position v] of [Sprite1 v])
- ThanksAnts_Thants
 - 
                            
						
						
                            Scratcher
                        
						
						 
63 posts
X and Y position help
Ohhh yeah.. I completely forgot/overlooked that block.
Thanks for reminding me.
                        
                        
                    Thanks for reminding me.
- duckboycool
 - 
                            
						
						
                            Scratcher
                        
						
						 
1000+ posts
X and Y position help
Donno, want to follow for followHello, replying to random topics is not the place for this. You should ask on people's profiles.
- mao56
 - 
                            
						
						
                            Scratcher
                        
						
						 
2 posts
X and Y position help
i just made the crosshair go to the mouse when mouse down? = true and when that happened i made the screen turn (you can do this in a single sprite)
like this:
when mouse down?
broadcast : crosshair go to mouse
broadcast : screen turn?
                        
                        
                    like this:
when mouse down?
broadcast : crosshair go to mouse
broadcast : screen turn?
- mao56
 - 
                            
						
						
                            Scratcher
                        
						
						 
2 posts
X and Y position help
Hi!I am making a point and shoot game and I need the bullet to go to where an actor following the mouse is. I was suggested to do this,
when I receive [ Shootv]
show
go to [gun v]
glide () secs to x: (Corss hair X) y: (Cross hair Y)
The problem is the cross hair moves a lot and I don't know how to get the position of the cross hair into the glide block!So if anyone could help with that it would be much appreciated.
it is scratch 3.0 you know
- Discussion Forums
 - » Help with Scripts
 - 
            »  X and Y position help 
         
            






 I am making a point and shoot game and I need the bullet to go to where an actor following the mouse is. I was suggested to do this,
 So if anyone could help with that it would be much appreciated.