Discuss Scratch

ScratchguyTutorials
Scratcher
4 posts

physics on scratch

hey guys, basically. when i try to make a physics engine on scratch and i stack 2 objects on top of eachother. they just keep on floating into the air. how do i fix this?
here is the project so you can see: https://scratch.mit.edu/projects/955318691/
– sorry if any of the code i put is not the same as the project, that is all i rememeber.

here is the code btw:

when i start as a clone:
forever
repeat until <(velocity) < (0)>
repeat until <<touching(ground)> or <touching(white)>>
change by (-1)
change y by (velocity)
end

change by (-3)
set to ((velocity) * (-1))
end
set to (0)
end

define :
repeat until <<not <touching ground> or <touching colour(white)>>
change y by (1)
end

PS: white is the outline colour of the objects
– i was 2 lazy to use the scratch blocks for this message

Last edited by ScratchguyTutorials (Jan. 24, 2024 05:56:28)

your_lucky-2
Scratcher
2 posts

physics on scratch

uhhh I thought it might be more complicated
nice!
GamingCat12345
Scratcher
100+ posts

physics on scratch

your_lucky-2 wrote:

uhhh I thought it might be more complicated
nice!
1.: they had an issue, this isn't a tutorial
2.: Please don't necropost
tidelgl
Scratcher
100+ posts

physics on scratch

when I start as a clone
forever
// Apply gravity
change [velocity v] by [-0.5]

// Vertical movement with collision detection
if <(velocity) < [0]> then
// Moving downward
repeat until <<touching [ground v]?> or <touching color [#FFFFFF]?>>
change y by (velocity)
end
set [velocity v] to ((velocity) * [-0.6]) // Bounce damping
snapToSurface // Custom block to prevent floating
else
// Moving upward
repeat until <<touching [ground v]?> or <touching color [#FFFFFF]?>>
change y by (velocity)
end
set [velocity v] to [0] // Stop when hitting ceiling
end

// Prevent micro-movements when resting
if <(abs (velocity)) < [0.2]> then
set [velocity v] to [0]
end
end

define snapToSurface
repeat until <not <touching [ground v]?>>
change y by [1]
end
repeat until <touching [ground v]?>
change y by [-1]
end

Powered by DjangoBB