Discuss Scratch

BlueyBlob
Scratcher
2 posts

wall collision

can anybody help with this? I'm making a simple physics jumping test thingy using velocity variables, after following another post the code is gave didnt quite work, this is the current code:

sprite 2 is the floor

if there's any more needed info just ask
mmhmBeans
Scratcher
500+ posts

wall collision

I don't understand your script, but here's how to do wall collision (I already answered on another topic)

First, make a “hitbox” costume. It should be a square, sized slightly smaller than the sprite itself.
Use these blocks instead of the normal movement ones:

define change x by (steps)
set [previous costume v] to (costume [name v]::looks)
switch costume to [hitbox v]
set rotation style [don't rotate v]
change x by (steps)
if <touching [wall v]?> then
change x by ((-1)*(steps))
end
switch costume to (previous costume)
set rotation style [all around v]

define change y by (steps)
set [previous costume v] to (costume [name v]::looks)
switch costume to [hitbox v]
set rotation style [don't rotate v]
change y by (steps)
if <touching [wall v]?> then
change y by ((-1)*(steps))
end
switch costume to (previous costume)
set rotation style [all around v]

define move (steps) steps
change x by (([sin v] of (direction))*(steps))::custom
change y by (([cos v] of (direction))*(steps))::custom

Oof this page took like 2 min to load scratch is really ded rn
BlueyBlob
Scratcher
2 posts

wall collision

mmhmBeans wrote:

I don't understand your script, but here's how to do wall collision (I already answered on another topic)

First, make a “hitbox” costume. It should be a square, sized slightly smaller than the sprite itself.
Use these blocks instead of the normal movement ones:

define change x by (steps)
set [previous costume v] to (costume [name v]::looks)
switch costume to [hitbox v]
set rotation style [don't rotate v]
change x by (steps)
if <touching [wall v]?> then
change x by ((-1)*(steps))
end
switch costume to (previous costume)
set rotation style [all around v]

define change y by (steps)
set [previous costume v] to (costume [name v]::looks)
switch costume to [hitbox v]
set rotation style [don't rotate v]
change y by (steps)
if <touching [wall v]?> then
change y by ((-1)*(steps))
end
switch costume to (previous costume)
set rotation style [all around v]

define move (steps) steps
change x by (([sin v] of (direction))*(steps))::custom
change y by (([cos v] of (direction))*(steps))::custom

Oof this page took like 2 min to load scratch is really ded rn

thanks. also yeah tbh i didn't really understand the code either as this was my first time making physics based movement but this really helped, thanks!

Powered by DjangoBB