Basically the title. In my particular case I am trying to make one sprite "sense" the other. As they go across the screen if one sprite touches the other I want to make that sprite (the one in motion) move up or down (depending on which motion would cause the one to avoid the other) a set value, and continue on its course across the screen.
Also is there any way for one sprite to "sense" the distance from it to the other?
Offline
whatisnttaken wrote:
Basically the title. In my particular case I am trying to make one sprite "sense" the other. As they go across the screen if one sprite touches the other I want to make that sprite (the one in motion) move up or down (depending on which motion would cause the one to avoid the other) a set value, and continue on its course across the screen.
Also is there any way for one sprite to "sense" the distance from it to the other?
[blocks]
<touching[ other sprite
<distance to[ other sprite
[/blocks]
Note that in both cases above, you need to select the other sprite from the pulldown list that is built into the block. Also note that the other sprite must have been previously added to the project to be included in the pulldown list.
Last edited by dbal (2008-06-06 14:40:35)
Offline
Say I wanted to have one sprite perform a certain function at a set distance from another sprite? Is that possible?
Offline
whatisnttaken wrote:
Say I wanted to have one sprite perform a certain function at a set distance from another sprite? Is that possible?
Yes, but at this point, I am going to refer you to a set of online tutorials and let you start studying about how to program in Scratch instead of just giving you the solution. Click on the link to Scratch in my signature below.
Offline
This is the script I have. When I move sprite 3 near sprite 2 nothing happens. What mistake have I made? I tried to follow the script as outlined by coolstuff.
<when green flag clicked><forever if><( <>> 50 )><distance to[ sprite2]<forever><broadcast[ move]
<when I receive[move]<repeat(10)<wait(.1<change y by(10 )secsc><stop script>
Offline
Upload your project as it stands and we can have a look at the problem more easily.
Offline
it's actually a complicated problem. here's a simple way to do it, where one sprite rotates when it gets too close to the other one (the direction it rotates depends upon which side is closer to the bad guy).
http://scratch.mit.edu/projects/Cyfarwyddyd/186136
as mayhem says, there's nothing better than posting it, though.
Offline
actually, i see from the first post that you just want to make the sprite go back and forth. that makes it easier:
http://scratch.mit.edu/projects/Cyfarwyddyd/186184
Offline
Thanks for all the replies.
My general idea is to make two sprites avoid each other no matter the conditions. i.e. random motion, etc. I understand the principle of of "distance to" and "if touching" but it doesn't seem to work as it should in my simulation. I have tried several models. In several cases using a sprite as a "background" to highlight the path the other sprite would take. I ultimately, however, wish to create such a simulation without using one sprite as a background. I am simply unsure of what I am doing incorrectly. I believe I am over complicating things, espcially with the scripts of the "background sprites".
How do I upload my projects?
Offline