Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with player collision
- DepthOfDistruct
- Scratcher
77 posts
Help with player collision
Hello, I have a problem with player collision where they will clip through blocks and sometime get stuck, lagging the game, help us appreciated
Here's the link
https://scratch.mit.edu/projects/649975060/
Here's the link
https://scratch.mit.edu/projects/649975060/
- TheCommCraft
- Scratcher
500+ posts
Help with player collision
try this for for the move (x) (y) script in the player sprite
define move(x)(y)
repeat ([abs] of (y))
change y by ((y momentum) / ([abs] of (y)))
if <touching [tiles] ?> then
change y by ((-1) * ((y momentum) / ([abs] of (y))))
set [y momentum] to [0]
set [x momentum] to ((x momentum) / [2])
end
end
repeat ([abs] of (x))
change x by ((x momentum) / ([abs] of (x)))
if <touching [tiles] ?> then
change x by ((-1) * ((x momentum) / ([abs] of (x))))
set [x momentum] to [0]
set [y momentum] to ((y momentum) / [2])
end
end
- DepthOfDistruct
- Scratcher
77 posts
Help with player collision
Thanks. FYI the reason it does that is because of the y momentum = 0 it will move upward and clip inside of the pipe tile, so when it tries to get out using the (repeat until not touching) script it moves upwards, this'll fix thanks.
- Discussion Forums
- » Help with Scripts
- » Help with player collision