Discuss Scratch

Nico9o7
Scratcher
5 posts

collision with movement physics in game

https://scratch.mit.edu/projects/1045756441/

How can i make my sprite (greaseball) not collide with certain colors? i was thinking
iftouchingcolor?thenrepeatuntilnottouchingcolor?moveoppositedirectionsteps

thanks!

Last edited by Nico9o7 (July 19, 2024 21:48:47)

TheCreatorOfUnTV
Scratcher
1000+ posts

collision with movement physics in game

You might want to put that in a custom block:
iftouchingcolor?thengotoopposite check "run without screen refresh"definegotooppositemove-1*speedsteps
bsteichman
Scratcher
500+ posts

collision with movement physics in game

TheCreatorOfUnTV wrote:

You might want to put that in a custom block:
iftouchingcolor?thengotoopposite check "run without screen refresh"definegotooppositemove-1*speedsteps
why would run without screen refresh matter here? there's no loops



anyways here's what i'd do

definemovestepsmovestepsstepsiftouchingcolor?thenmove-stepssteps

Last edited by bsteichman (July 20, 2024 02:08:11)

Nico9o7
Scratcher
5 posts

collision with movement physics in game

Thanks for the help, but neither work. maybe if i dont figure out the collision physics i can always use ol' reliable
iftouchingcolor?thengotox:0y:0
bsteichman
Scratcher
500+ posts

collision with movement physics in game

Nico9o7 wrote:

Thanks for the help, but neither work. maybe if i dont figure out the collision physics i can always use ol' reliable
iftouchingcolor?thengotox:0y:0
that's weird because i got it to work on my end
bsteichman
Scratcher
500+ posts

collision with movement physics in game

i changed your movement physics block to this:
definemovementphysicsspeedfrictionchangexvelbykeydpressed+0-keyapressed*speedsetxveltoxvel*frictionchangexbyxveliftouchingcolor?thenchangexby-xvelsetx veltoxvel*-1*how bouncy input how bouncy you want the collisions to be on a scale from 0-1 added thischangeyvelbykeywpressed+0-keyspressed*speedsetyveltoyvel*frictionchangeybyyvelsety veltoyvel*-1*how bouncy

same principle as my previous response.

note: you can have it more bouncy than a value of 1, but it'll act like a trampoline and will bounce with more speed than you put into it

Last edited by bsteichman (July 20, 2024 22:48:59)

Nico9o7
Scratcher
5 posts

collision with movement physics in game

bsteichman wrote:

i changed your movement physics block to this:
definemovementphysicsspeedfrictionchangexvelbykeydpressed+0-keyapressed*speedsetxveltoxvel*frictionchangexbyxveliftouchingcolor?thenchangexby-xvelsetx veltoxvel*-1*how bouncy input how bouncy you want the collisions to be on a scale from 0-1 added thischangeyvelbykeywpressed+0-keyspressed*speedsetyveltoyvel*frictionchangeybyyvelsety veltoyvel*-1*how bouncy

same principle as my previous response.

note: you can have it more bouncy than a value of 1, but it'll act like a trampoline and will bounce with more speed than you put into it

the code worked partly! the y velocity is slower if you dont put it in the if _ then block. something like this:

iftouchingcolor?thenchangexby-xvel.setx vel.toxvel*-1*bouncychangeyby-yvel.sety vel.toyvel*-1*anythingabove1.2worksbest

Powered by DjangoBB