Discuss Scratch

theRealMC_Creeper
Scratcher
23 posts

Help with a physics engine.

Hey there, I'm making a physics engine in one sprite without the pen tool and without Turbowarp, which from what people said is hard/impossible. So far I made three variables: gravity, bounce, and I.D.. I can tweak these so the object will move differently, for example if I want a bowling ball I'll lower the bounce and raise the gravity(btw these variables are for this sprite only so the numbers are unique to each clone). What I'm wondering is how would I add horizontal movement and have it be affected by slopes and maybe curves? And how would I improve on my scripts to get it working better?

VVV The scripts VVV

when green flag clicked
hide
set [I.D.] to [-1]
repeat (3)
change [I.D.] by (1)
create clone of [myself]
wait (0) secs

end

when I start as a clone
show
if <(I.D.) = [0]> then
hide
go to x: (0) y: (-180)



else
if <(I.D.) = [1]> then
point in direction (90)
go to x: (0) y: (0)
switch costume to [floor test]



else
set rotation style [draggable]
point in direction (90)
set [velocity] to [0]
go to x: (0) y: (0)
go to front
show
switch costume to [ball]
forever
if <touching color [#000000]?> then
set [velocity] to (((velocity) * (-1)) * (bounce))


else
if <not <[velocity] = ((gravity) * (1.5))>> then
change [velocity] by ((0.1) * (gravity))

end

end
move (velocity) steps
end

end

end

If you're able to help I'd be very grateful.
orangetheory
Scratcher
500+ posts

Help with a physics engine.

make left slopes a different color, and make slopes facing right a different color.
To make it look cleaner make it very thin but not too thin and also a color similar to the one you are using regularly.
Then act upon those slopes using your code.

-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!

The forum helpers, a place where we help people in the forums
orangetheory
Scratcher
500+ posts

Help with a physics engine.

Or, you could make the objects act upon the slope using the tangent of the angle of the slope.

-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!

The forum helpers, a place where we help people in the forums

Powered by DjangoBB