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

#1 2009-05-01 18:16:05

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Bouncing off other sprites, how?

I posted a question for archmage, but I am curious if someone else has worked out the math for this...

http://scratch.mit.edu/projects/archmage/72848

Let's say you have 2 cat sprites, how would you modify the script to make the cats bounce off each other as if they are solid?

Nothing I try works out the way it should.


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#2 2009-05-01 18:25:29

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Bouncing off other sprites, how?

What about setting the x variable to multiply -1 or something. Lemme work on something to see.

Offline

 

#3 2009-05-01 18:26:37

dingdong
Scratcher
Registered: 2007-08-09
Posts: 1000+

Re: Bouncing off other sprites, how?

alrighty well then we can have several methods for this

-the first is simple and can just seem stupid at sometimes, but here goes...

[forever]
[if <touching [cat sprite2]>]
[point in direction (direction) - (180)]

-since the cat is outlined with black we can use that a base for color detection, this technique could be done in two ways, but I am demonstrating the form that allows you  to control the areas that turn that cat if the cat isn't completely covered in the detection color

[forever]
[if <color [chosen detection color] is touching [black]>]
[point in direction (direction) - (180)]

-I could go on for days showing different techniques, but most are obsolete, these two are the easiest and best, you can change the turning amount in various ways, some can be more complex so you can create realistic pyshics


http://img851.imageshack.us/img851/2829/superanbanner.png
click the image for my music

Offline

 

#4 2009-05-01 18:31:08

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Bouncing off other sprites, how?

Here, if this is what you meant http://scratch.mit.edu/projects/keroro645/510107

Offline

 

#5 2009-05-01 18:37:58

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Bouncing off other sprites, how?

keroro645 wrote:

Here, if this is what you meant http://scratch.mit.edu/projects/keroro645/510107

Not bad, but you have removed too much of the script.  I still want to have jumping. And, the cat is moving way too slow.

Last edited by BoltBait (2009-05-01 18:39:25)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#6 2009-05-01 18:38:58

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Bouncing off other sprites, how?

dingdong wrote:

alrighty well then we can have several methods for this

-the first is simple and can just seem stupid at sometimes, but here goes...

[forever]
[if <touching [cat sprite2]>]
[point in direction (direction) - (180)]

-since the cat is outlined with black we can use that a base for color detection, this technique could be done in two ways, but I am demonstrating the form that allows you  to control the areas that turn that cat if the cat isn't completely covered in the detection color

[forever]
[if <color [chosen detection color] is touching [black]>]
[point in direction (direction) - (180)]

-I could go on for days showing different techniques, but most are obsolete, these two are the easiest and best, you can change the turning amount in various ways, some can be more complex so you can create realistic pyshics

This was the first thing I tried but it doesn't really work.  There are cases where the sprites just start flipping out... left/right/left/right/left/right really fast.

Last edited by BoltBait (2009-05-01 18:42:59)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#7 2009-05-01 18:41:19

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Bouncing off other sprites, how?

BoltBait wrote:

keroro645 wrote:

Here, if this is what you meant http://scratch.mit.edu/projects/keroro645/510107

Not bad, but you have removed too much of the script.  I still want to have jumping. And, the cat is moving way too slow.

Ok I'll add some more to it.

Offline

 

#8 2009-05-01 18:48:12

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Bouncing off other sprites, how?

Sigh this is too hard for me, I tried.

Offline

 

#9 2009-05-01 18:58:08

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Bouncing off other sprites, how?

keroro645 wrote:

Sigh this is too hard for me, I tried.

Well, now you know how I feel.  big_smile


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#10 2009-05-01 19:51:59

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Bouncing off other sprites, how?

I'd totally forgotten about this post I'd made here:

http://scratch.mit.edu/forums/viewtopic.php?id=5326&p=3

I bet I can get this to work in that scenario...

Both sprites should point away from each other and move until they no longer touch.

Last edited by BoltBait (2009-05-01 20:11:49)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#11 2009-05-01 20:37:14

ScratchMusicGroup
Scratcher
Registered: 2009-04-12
Posts: 100+

Re: Bouncing off other sprites, how?

yeah i tried to do that too it would be great for games and i bet you are looking for a way that uses the least sripcts right?


http://i44.tinypic.com/2yjx4ht.jpg                  http://i44.tinypic.com/xljspe.png        http://i40.tinypic.com/16c3rdi.png        http://i39.tinypic.com/16jowol.png

Offline

 

#12 2009-05-01 20:45:28

cheddargirl
Scratch Team
Registered: 2008-09-15
Posts: 1000+

Re: Bouncing off other sprites, how?

One of Paddle2See's projects might help you out: (http://scratch.mit.edu/projects/Paddle2See/446524). Admittedly, the movements are not too entirely accurate, but maybe you can utilize the code as a way to figure out your dilemma.


http://i.imgur.com/8QRYx.png
Everything is better when you add a little cheddar, because when you have cheese your life is at ease  smile

Offline

 

#13 2009-05-02 10:31:57

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: Bouncing off other sprites, how?

I developed a project some time ago to do exactly what you are trying (for ball-shaped sprites):

http://scratch.mit.edu/projects/s_federici/155861

The author of the script is Colkadome. Let me know how this works for you.

Offline

 

#14 2009-05-02 10:38:16

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Bouncing off other sprites, how?

This seems kinda difficult to do in scratch
Usually when programming these kinds of thing I refer to newgrounds
http://www.newgrounds.com/bbs/topic/398295

That is a topic explaining how to bounce off of uneven surfaces such as sprites. Unfortunately it uses Atan2 which scratch doesn't have.

If you don't really care for accuracy you could make the sprite point to your other sprite then move away from it.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#15 2009-05-04 21:49:39

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: Bouncing off other sprites, how?

Well, I got it to work.  It's not perfect, but very servicable...

http://scratch.mit.edu/projects/BoltBait/513961

I chose to use the

<point towards( other sprite )>
<turn cw( 180  )degrees>

because the sprite is probably pointing toward the other sprite anyway, so this was less complicated than using the math method.


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

Board footer